JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 8th, 2004, 09:24 AM
jackson17 jackson17 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 7 jackson17 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to jackson17
Unhappy PHP Form Validation - NEED HELP!!! please ;-)

Hi, Been working on this Order Form with Validation adding. Most of the validation rules work but when the validation doesn't work for the radio (buttons) that i have within the order form.

Here's the code:

Code:
<title>Border Prints Order Form</title>
<!---Border Prints - Order Form Validate--->
<script>
<!-- 
function MM_findObj(n, d) { //v3.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_validateForm() { //v3.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida  teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '· '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) have occurred:\n\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
<center><form onSubmit='return validForm(this)' action=send.php method=post>
<font face=arial><font size=2><font color=darkblue>
Your Name:<br><input type=text name=name><br>
Your Email Address:<br><input type=text name=email><br>
Your Home Address:<br><input type=text name=address><br>
Your Postcode:<br><input type=text name=postcode><br>
Town / City:<br><input type=text name=towncity><br>
Choose mount colour:<br>
<input type=radio name="mountcolour" value= "green">green <input type=radio name="mountcolour" value= "cream">cream <input type=radio name="mountcolour" value= "fawn">fawn<br>
Choose mount size:<br>
<input type=radio name="mountsize" value= "10x8">10x8 <font size=1>(7.5 x 5.5 aperture)<font size=2> <input type=radio name="mountsize" value= "10x8">10x8 <font size=1>(7 x 5 aperture)<font size=2><br><br>
ENTER ORDER CODE:<br><font color= darkblue>
<input type=text name=subject value=''><font color=red><br><br><font color=darkblue>
<input type=submit value='Send order' onClick="MM_validateForm('name','','R','email','','RisEmail  ','address','','R','towncity','','R','postcode',''  ,'R','mountcolour','','R','mountsize','','R','subject','','R','');return document.MM_returnValue" style="font: normal 11px arial;"> <input type=reset value='Reset order' style="font: normal 11px arial";>
</center>

____
The mountcolour and mountsize - are both Radio Buttons, which doesn't seem to be recognized with my validation for sum reason

Any help would be greatfully received!!

Last edited by dhouston : April 8th, 2004 at 03:24 PM. Reason: Wrapping code in code tags for legibility's sake. Also moved question to appropriate forum.

Reply With Quote
  #2  
Old April 15th, 2004, 09:11 AM
masood masood is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 8 masood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That code is a mess... I say just start over.... here is a simple example of validation:


Code:
  
<SCRIPT LANGUAGE="JAVASCRIPT">
function validate_form(fRef)
 {
 var notChecked = true;
 if (fRef.first_name.value == "") 
	{
	alert("Please enter your first name");
	fRef.first_name.focus();
	return false;
	}
 if (fRef.last_name.value == "") 
	{
	alert("Please enter your lastname");
	fRef.last_name.focus();
	return false;
	}
 for (i = 0; i < fRef.sex.length; i++)
	{
 if (fRef.sex[i].checked == true)
	{
	notChecked = false;
	}   
	}
 if (notChecked == true)
	{
 alert("Please indicate your sex");
 fRef.sex[0].focus();
 return false;
	}
 alert("yep, it worked");
 return false; // remove this line for production mode
 }
</SCRIPT>
<FORM NAME="myForm" onSubmit="return validate_form(this);">
First Name:<INPUT TYPE="TEXT" NAME="first_name"><BR>
Last Name:<INPUT TYPE="TEXT" NAME="last_name"><BR>
Sex: <INPUT TYPE="RADIO" NAME="sex" VALUE="Male">Male&nbsp;&nbsp;<INPUT TYPE="RADIO" NAME="sex" VALUE="Female">Female
<INPUT TYPE="SUBMIT">
</FORM>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > PHP Form Validation - NEED HELP!!! please ;-)


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 3 hosted by Hostway