/    Sign up×
Community /Pin to ProfileBookmark

Form Validation Issue

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”>[/CODE]

The original is just:

[CODE]<form name=form method=”post” action=””>[/CODE]

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>[/CODE]

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!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@trailerparkboyauthorAug 17.2011 — Didn't figure out what the issue was, but did find a different script that works and I'm using.
×

Success!

Help @trailerparkboy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...