SunQuest
           Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old April 28th, 2003, 02:16 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Javascript, a little php and form validation

Hello...
I am having difficulties, I can get the email validation to work for that field, but when I try and get the form validation to include the email validation, it won't work...
Help someone!!! Before i throw the PC out the window.


<SCRIPT LANGUAGE="JavaScript">

//This is the email validation:
function validate_email(field) {
var email = new String(field)
var index=email.indexOf("@");
if(index>0) {
var pindex=email.indexOf(".",index);
if ((pindex>index+1) && (email.length>pindex+1))
return true;
}
alert("Enter valid email");
field.focus();
field.select();
return false;
}

//this is the form validation

function validate(form) {
var submitform = true;
var manfields = "The following fields are Mandatory;nn";

if (form.username.value == '') {
submitform = false;
manfields += "Usernamen";
}

if (form.email.value == '') {
submitform = false;
manfields += "Usernamen";
}

if (submitform == false) {
alert(manfields);
return false;
}
}
</SCRIPT>

/*THis is the table that appears with the different fields users input, i have taken off most fields and just included username and email here, when not filled in the user can not submit this page until there is something there */

echo "<FORM NAME="u_form" METHOD="POST" ACTION="$PHP_SELF" onSubmit="return validate(this);">
echo "<INPUT TYPE="hidden" NAME="username" VALUE="$username">n";
echo "<INPUT NAME="email" TYPE="text" VALUE="$email" onChange="trim(this);validate_email(this)">n";


/* the text boxes work, it has been since i added a seperate function to validate the email that I can not get it to work. However the validation does work for the email, just will not work when I try and get it to stop the submision of the form.

I have tried adding to the validate form function a check that see's if the validate email passed true or false... it will alert the user to correct the email, but will still allow the user to submit the form even though email is wrong....
help!!

if more information is needed i can add it!
*/

Reply With Quote
  #2  
Old April 28th, 2003, 02:52 PM
crisp crisp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Holland
Posts: 336 crisp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Javascript, a little php and form validation

Try this, and forget about the email validation function you have now:

php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. function validate(form) {
  5.  
  6.   var submitform = true;
  7.   var errortext = "The following errors were encountered;nn";
  8.  
  9.   if (form.username.value == '') {
  10.     submitform = false;
  11.     errortext += "Username is a mandatory fieldn";
  12.   }
  13.  
  14.   if (form.email.value == '') {
  15.     submitform = false;
  16.     errortext += "Email is a mandatory fieldn";
  17.   } else if (!form.email.value.match(/^[A-Za-z0-9_-]+([.][A-Za-z0-9_-]+){0,4}[@][A-Za-z0-9_-]+([.][A-Za-z0-9_-]+){1,3}$/)) {
  18.     submitform = false;
  19.     errortext += "Entered Email is not validn";
  20.   }
  21.  
  22.   if (submitform == false) {
  23.     alert(errortext);
  24.     return false;
  25.   }
  26.  
  27. }
  28. ?>


(I put it in PHP tags, but it is javascript offcourse)

Reply With Quote
  #3  
Old April 28th, 2003, 03:24 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Javascript, a little php and form validation

It works!!
But i had to do it a little different, with the pattern as it's own variable and the match being == null to alert the user of invalid email.

But it works... and so much easier then what i was attempting.

Thank you!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Javascript, a little php and form validation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway