php mail form with redirect to same page
Posted: Wed May 19, 2010 2:46 pm
I am new here, so if this topic was covered elsewhere, please direct me. thanks in advance!!!
here is my form (php side):
<?
function checkOK($field)
{
if (eregi("\r",$field) || eregi("\r\n",$field)){
die("Invalid Input!");
}
}
$name=$_POST['name'];
checkOK($name);
$email=$_POST['email'];
checkOK($email);
$phone=$_POST['phone'];
checkOK($phone);
$comments=$_POST['comments'];
checkOK($comments);
$to="sample@sample.com";
$message="Name: $name\r\nPhone: $phone\r\nEmail: $email\r\nMessage: $comments\r\n";
if(mail($to,"Information Request",$message,"From: $email\r\n")) {
echo "Your request has been sent. We will contact you within 2 business days";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>
After the submit button is clicked, i want the words "form submitted" displayed above the form, and to NOT have the user redirected to another page.
If possible, to also make the original form invisible (not show) and just display "form submitted".
I have searched for this and found free forms that offer this, but want to design my own and keep it simple for future use.
If anyone can direct me to a "simple" solution or form that offers this:
1)email verification
2)field validation
3)spam protection
please let me know.
here is my form (php side):
<?
function checkOK($field)
{
if (eregi("\r",$field) || eregi("\r\n",$field)){
die("Invalid Input!");
}
}
$name=$_POST['name'];
checkOK($name);
$email=$_POST['email'];
checkOK($email);
$phone=$_POST['phone'];
checkOK($phone);
$comments=$_POST['comments'];
checkOK($comments);
$to="sample@sample.com";
$message="Name: $name\r\nPhone: $phone\r\nEmail: $email\r\nMessage: $comments\r\n";
if(mail($to,"Information Request",$message,"From: $email\r\n")) {
echo "Your request has been sent. We will contact you within 2 business days";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>
After the submit button is clicked, i want the words "form submitted" displayed above the form, and to NOT have the user redirected to another page.
If possible, to also make the original form invisible (not show) and just display "form submitted".
I have searched for this and found free forms that offer this, but want to design my own and keep it simple for future use.
If anyone can direct me to a "simple" solution or form that offers this:
1)email verification
2)field validation
3)spam protection
please let me know.