Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
I have a contact.php type form that is working (so far) how I would like, however, when the form is submitted, it doesn't redirect to the page I'm telling it to redirect to. Internet searches seem to have a very unanimous and simple solution, which is to write this code after the mail("...") code: header("Location: http://www.example.com/thankyou.html"); This I have done but it just won't redirect. Hoping for some suggestions. Here is the PHP code of my form: [code] $nameErr = $emailErr = $monthErr = ""; $name = $email = $month = $headers = $to =$subject = $body = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = test_input($_POST["name"]); $email = test_input($_POST["email"]); $month = test_input($_POST["month"]); $to = "information@purden.com"; $headers = "From: $email \r\n"; $subject = "Rentals Reservation Request"; $body .= "\r\n Name: " . $name; $body .= "\r\n Email: " . $email; $body .= "\r\n Month: " . $month; } function test_input($data){ $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "<font color='red'>Name is required</font>"; $error .= "<li>Name is required. </li>"; } else { $name = test_input($_POST["name"]); } if (empty($_POST["email"])) { $emailErr = "<font color='red'>Email is required</font>"; $error .= "<li>Email is required.</li>"; } else { $email = test_input($_POST["email"]); } if (empty($_POST["month"])) { $monthErr = "Enter a month from the drop-down list"; $error .= "<li>Month is required.</li>"; } else { $month = test_input($_POST["month"]); } $name = test_input($_POST["name"]); if (!preg_match("/^[a-zA-Z-' ]*$/",$name)) { $nameErr = "<font color='red'>Only letters and spaces allowed"; } $email = test_input($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "<font color='red'>Invalid email format"; $error .= "<li>Invalid email format. </li>"; echo '<p class="error"><strong>Your message was NOT sent<br/> The following error(s) occurred:</strong><br/>'. '<ul>' . $error . '</ul>' . '</p>'; } else { mail($to, $subject, $body, $headers); header("Location: http://www.mywebsite.com/rentals_reservation_thankyou.html"); } } [code] |
||||
|
The easiest way would be to set the action to the page you want to redirect to, and put the PHP onto that page instead. |
||||
|
Hello! Now after submit the page go up in the header, wich is the code for have the page keep in the position of the form, so a user can read the status message? Or a code to redirect to another page? |
||||
|
You could probably put the status message on the top of the page, maybe, as simple workaround. Otherwise you could write out a javascript in your error message which also scrolls to it, which is a bit more difficult. For redirecting to another page, do it like I wrote above: The easiest way would be to set the action to the page you want to redirect to, and put the PHP onto that page instead.
|
|