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.
php mail form with redirect to same page
Moderator: General Moderators
Re: php mail form with redirect to same page
These are big topics. I recommend doing some searches for each of them and working out the solution on your own. That's by far the best method, and you'll learn more doing it that way.xmatter wrote:1)email verification
2)field validation
3)spam protection
To handle this, I prefer to have the form submit to a different page. That page handles the form data _silently_, then automatically redirects back to the original page with error code(s) and status. Based on those, you can choose whether or not to display the form. An easy way to pass information back and forth between pages is with sessions. If you really want to stay on the same page though, the principle is the same. Create a flag of some sort based on the submitted information and draw the form if flag is true, otherwise don't.xmatter wrote: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".