Page 1 of 1

PHP form validation errors

Posted: Fri Aug 29, 2008 4:01 pm
by dirtyvegas14
Whenever I fill out the form located at http://www.edmontonrush.com/rush_rewards/form.php I get the error "Please fill out all the required fields." every time and I'm not sure how to fix it. The fields for "age, grade, school, and parentname" were the new ones I added from an existing form that worked and now that I try to make them mandatory fields to fill out, the form does not send at all.

Thanks-

Re: PHP form validation errors

Posted: Fri Aug 29, 2008 4:23 pm
by The_Anomaly
dirtyvegas14 wrote:Whenever I fill out the form located at http://www.edmontonrush.com/rush_rewards/form.php I get the error "Please fill out all the required fields." every time and I'm not sure how to fix it. The fields for "age, grade, school, and parentname" were the new ones I added from an existing form that worked and now that I try to make them mandatory fields to fill out, the form does not send at all.

Thanks-
First off, this is all javascript. As such, it should be in the client-side forum.

Nevertheless, you've set your validation function to be called "onblur" of the contactname field. That's what's causing your problem, as it tries to validate when you go to the next field.

Re: PHP form validation errors

Posted: Fri Aug 29, 2008 6:09 pm
by dirtyvegas14
thanks for the reply. I'm a graphic designer with very little programming knowledge. Can someone help with this code?

<style type="text/css" media="screen">
@import url("../css/layout.css");
</style>


<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
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[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args);
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 (isNaN(val)) 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) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>



<form action="" method="post">
<table width="100%">

<tr>
<td class="td_underline"><span class="redhighlight">*</span>Contact Name </td>
<td colspan="2" class="td_underline"><input name="contactname" type="text" onblur="MM_validateForm('contactname','','R','age','','R','grade','','R','school','','R','parentname','','R','phone','','R','email','','R');return document.MM_returnValue" value="" size="25" /></td>
</tr>
<tr>
<td class="td_underline"><span class="redhighlight">*</span>Age</td>
<td colspan="2" class="td_underline"><input type="text" name="age" size="25" value="" /></td>
</tr>
<tr>
<td class="td_underline"><span class="redhighlight">*</span>Grade</td>
<td colspan="2" class="td_underline"><input type="text" name="grade" size="25" value="" /></td>
</tr>
<tr>
<td class="td_underline"><span class="redhighlight">*</span>School</td>
<td colspan="2" class="td_underline"><input type="text" name="school" size="25" value="" /></td>
</tr>
<tr>
<td class="td_underline"><span class="redhighlight">*</span>Parent's Names</td>
<td colspan="2" class="td_underline"><input type="text" name="parentname" size="25" value="" /></td>
</tr>
<tr>
<td class="td_underline"><span class="redhighlight">*</span>Daytime Phone #</td>
<td colspan="2" class="td_underline"><input name="phoneareacode" type="text" id="phoneareacode" value="" size="3" />
<input type="text" name="phone" size="20" value="" /></td>
</tr>

<tr>
<td class="td_underline"><span class="redhighlight">*</span>E-mail Address</td>
<td colspan="2" class="td_underline"><input type="text" name="email" size="25" value="" /></td>
</tr>
<tr>
<td class="td_underline"><input name="submit" type="submit" id="submit" value="Submit Form" />
<input type="hidden" name="id" value="1" /></td>
<td colspan="2" class="td_underline"><input name="reset" type="reset" id="reset" value="Reset" /></td>
</tr>
</table>
</form>