Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > RocketCake
Redirect a contact from after submit

emvie468
Registered User
Quote
2020-10-18 22:32:35

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]


niko
Moderator
Quote
2020-10-19 11:59:00

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.


faxuno
Registered User
Quote
2020-12-28 13:03:22

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?


niko
Moderator
Quote
2020-12-29 06:53:48

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.



Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Int?rnational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact