Hello,
I’ve added a script to validate my form before the form results are passed on to my .php script and emailed to me.
Issue is that while the validation is catching my empty mandatory fields, once the user is alerted and clicks OK, the form is sent anyways without requiring to populate the missing fields.
The only thing I think is different from the original script I copied from this line:
[CODE]<form name=form action=”send_mail.php” method=”post”>
The original is just:
[CODE]<form name=form method=”post” action=””>
So not sure if this is why sends automatically?
Here’s the complete code if anyone can spot the real cause:
[CODE]<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
function verify() {
var themessage = “You are required to complete the following fields: “;
if (document.form.custname.value==””) {
themessage = themessage + ” – Name”;
}
if (document.form.custemail.value==””) {
themessage = themessage + ” – Email”;
}
if (document.form.custphone.value==””) {
themessage = themessage + ” – Phone”;
}
//alert if fields are empty and cancel form submit
if (themessage == “You are required to complete the following fields: “) {
document.form.submit();
}
else {
alert(themessage);
return false;
}
}
// End –>
</script>
</head>
<body>
<p><strong>FREE Renovation Consultation</strong></p>
<p>We offer a free, no obligation consultation in your home.</p>
<form name=form action=”send_mail.php” method=”post”>
<p>Name* <input type=text name=”custname” size=”20 value=”” maxlength=”50″ /></p>
<p>Email* <input type=text name=”custemail” size=”35″ value=”” maxlength=”100″ /></p>
<p>Phone* <input type=text name=”custphone” size=”35″ value=”” maxlength=”50″ /></p>
<p>City <input type=”text” size=”35″ name=”custcity” value=”” maxlength=”50″ /></p>
<p>
Areas of Interest:<br/>
<input type=”checkbox” name=”formDoor[]” value=”Interior Design” />Interior Design<br />
<input type=”checkbox” name=”formDoor[]” value=”Renovation” />Renovation<br />
<input type=”checkbox” name=”formDoor[]” value=”Kitchen” />Kitchen<br />
<input type=”checkbox” name=”formDoor[]” value=”Bathroom” />Bathroom<br />
<input type=”checkbox” name=”formDoor[]” value=”Basement” />Basement<br />
<input type=”checkbox” name=”formDoor[]” value=”Home Staging” />Home Staging<br />
<input type=”checkbox” name=”formDoor[]” value=”Other” />Other<br />
</p>
<input type=”submit” name=”formSubmit” value=”Submit” onclick=”verify();”/>
</form>
I was going to do the validation in my php script, but couldn’t get working so thought I’d try a javascript solution.
Thanks!