kristingish
Programmer
- Jun 6, 2008
- 2
I am currently trying to fix a problem on the form submission on my site.
On the Request Information page I am using MM_validateForm function and the FormtoEmail.php script.
When required fields are blank, you are alerted via pop-up notification when hitting submit. Afterwards though, the form still sends without letting you finish completing required fields. I have noticed that if the First Name field is blank the form will not send, but any other field it just still sends.
I have looked this up on Google endlessly and have tried every 'fix'.
This is the function:
This is the form html code:
This is the code on the submit button:
On the Request Information page I am using MM_validateForm function and the FormtoEmail.php script.
When required fields are blank, you are alerted via pop-up notification when hitting submit. Afterwards though, the form still sends without letting you finish completing required fields. I have noticed that if the First Name field is blank the form will not send, but any other field it just still sends.
I have looked this up on Google endlessly and have tried every 'fix'.
This is the function:
Code:
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
if (document.getElementById){
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=document.getElementById(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 Email Address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' Must Contain a Valid Phone 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('Please Complete All Required Fields:\n'+errors); }
document.MM_returnValue = (errors ==');
} }
//-->
This is the form html code:
Code:
<form action="FormToEmail.php" method="post" name="myform" class="cmxform" id="myform" onsubmit="MM_validateForm('first-name',','R');MM_validateForm('last-name',
','R');MM_validateForm('workphone',','RisNum');MM_validateForm('address1',
','R');MM_validateForm('city',','R');MM_validateForm('state',','R');
MM_validateForm('country',','R');return document.MM_returnValue;">
This is the code on the submit button:
Code:
<input type="submit" class="buttons" onClick="MM_validateForm('first-name',','R');MM_validateForm('last-name',
','R');MM_validateForm('workphone',','RisNum');MM_validateForm('address1',
','R');MM_validateForm('city',','R');MM_validateForm('state',','R');
MM_validateForm('country',','R');return document.MM_returnValue;" value="Send"/>