PHP form with javascript validation won't send? [SOLVED]
Posted: Tue Aug 21, 2007 8:32 am
feyd | Please use
And here's my Form page with the validation:
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have a PHP email form with a javascript validation that just refuses to send! When all required fields are filled in, and the form submitted, instead of directing to the results page, it gives me the error message instead. When i take out all the javascript, it sends and works fine, so i realise it may be more of a java problem than a PHP one, but anyhelp would be appreciated. Thank you!
Here's my PHP page,Code: Select all
<?php
if(isset($_POST['submit'])) {
$to = "myemail@myemail.com";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message: $message\n";
header("Location: results.php");
mail($to, $subject, $body, "From: server@easyspace.com");
} else {
echo "blarg!";
}
?>Code: Select all
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Wayne Nolting (w.nolting@home.com) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.form.name.value=="") {
themessage = themessage + " - Name";
}
if (document.form.email.value=="") {
themessage = themessage + " - E-mail";
}
if (document.form.message.value=="") {
themessage = themessage + " - Message";
}
//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>
<form name=form method="post" action="mailer.php">
Name:
<input type="text" name="name" size="19"><br>
<br>
E-Mail:
<input type="text" name="email" size="19"><br>
<br>
Message:<br>
<textarea rows="9" name="message" cols="30"></textarea><br>
<br>
<input type=button value="Submit Request" onclick="verify();">
<input type=reset value="Clear Form"><br>
</form>
</body>
</html>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]