alexwdesigns
09-02-2008, 01:21 AM
hi guys I'm new to the forum. Anyway, I need help on this little problem. I have my form and validation set up with js, and a form submit through php. What I want to do is have the page NOT refresh on submit, and instead pop up a hidden field saying thank you, and I do realize the PHP will need to be replaced. Can anyone guide me to a tutorial, or walk me through it? Here's the code for the form validation and php.
<?php
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail( "awedderien@gmail.com", "Portfolio Contact Form",
$message, "From: $email" );
header( "Location: http://www.hi.com" );
?>
function checkForm() {
name = document.getElementById("name").value;
email = document.getElementById("email").value;
message = document.getElementById("message").value;
if (name == "") {
hideAllErrors();
document.getElementById("nameError").style.display = "inline";
document.getElementById("name").select();
return false;
} else if (email == "") {
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (email.indexOf("@") < 1) { // must contain @, and it must not be the first character
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (email.lastIndexOf(".") <= email.indexOf("@")) { // last dot must be after the @
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (email.indexOf("@") == email.length) { // @ must not be the last character
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (email.indexOf("..") >=0) { // two periods in a row is not valid
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (email.indexOf(".") == email.length) { // . must not be the last character
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (message == "") {
hideAllErrors();
document.getElementById("messageError").style.display = "inline";
document.getElementById("message").select();
document.getElementById("message").focus();
return false;
}
return true;
}
function hideAllErrors() {
document.getElementById("nameError").style.display = "none"
document.getElementById("emailError").style.display = "none"
document.getElementById("messageError").style.display = "none"
}
<form name="contact_form" method="post" onsubmit="return checkForm();" action="Scripts/mail.php">
<label for="name">Name</label><h5>(required)</h5>
<input id="name" name="name" type="text" /><br />
<div class="error" id="nameError">Required: Please enter your name.<br /></div><br />
<label for="email">Email</label><h5>(required)</h5>
<input id="email" name="email" type="text" /><br />
<div class="error" id="emailError">Required: Please enter a valid email address.<br /></div><br />
<label for="message">Message</label><h5>(required)</h5>
<textarea name="message" id="message"</textarea><br />
<div class="error" id="messageError">Required: Please enter a message.<br /></div><br />
<button type="submit" id="submit_btn" value="Submit" >Send</button><br />
</form>
[/PHP]
<?php
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail( "awedderien@gmail.com", "Portfolio Contact Form",
$message, "From: $email" );
header( "Location: http://www.hi.com" );
?>
function checkForm() {
name = document.getElementById("name").value;
email = document.getElementById("email").value;
message = document.getElementById("message").value;
if (name == "") {
hideAllErrors();
document.getElementById("nameError").style.display = "inline";
document.getElementById("name").select();
return false;
} else if (email == "") {
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (email.indexOf("@") < 1) { // must contain @, and it must not be the first character
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (email.lastIndexOf(".") <= email.indexOf("@")) { // last dot must be after the @
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (email.indexOf("@") == email.length) { // @ must not be the last character
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (email.indexOf("..") >=0) { // two periods in a row is not valid
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (email.indexOf(".") == email.length) { // . must not be the last character
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
return false;
} else if (message == "") {
hideAllErrors();
document.getElementById("messageError").style.display = "inline";
document.getElementById("message").select();
document.getElementById("message").focus();
return false;
}
return true;
}
function hideAllErrors() {
document.getElementById("nameError").style.display = "none"
document.getElementById("emailError").style.display = "none"
document.getElementById("messageError").style.display = "none"
}
<form name="contact_form" method="post" onsubmit="return checkForm();" action="Scripts/mail.php">
<label for="name">Name</label><h5>(required)</h5>
<input id="name" name="name" type="text" /><br />
<div class="error" id="nameError">Required: Please enter your name.<br /></div><br />
<label for="email">Email</label><h5>(required)</h5>
<input id="email" name="email" type="text" /><br />
<div class="error" id="emailError">Required: Please enter a valid email address.<br /></div><br />
<label for="message">Message</label><h5>(required)</h5>
<textarea name="message" id="message"</textarea><br />
<div class="error" id="messageError">Required: Please enter a message.<br /></div><br />
<button type="submit" id="submit_btn" value="Submit" >Send</button><br />
</form>
[/PHP]