I have read all the previous questions regarding redirecting to another url after a php form is successfully submitted, but I am having trouble doing this myself and would greatly appreciate any help you might be able to give me!
<?php
require_once("included_functions.php");
if (($_SERVER['REQUEST_METHOD'] == 'POST') && (!empty($_POST['action']))):
$name = $_POST['name'];
$email = $_POST['email'];
$fictioninterest = $_POST['fictioninterest'];
$bookclub = $_POST['bookclub'];
$newsletter = $_POST['blogtalk'];
$blogtalk = $_POST['blogtalk'];
$skype = $_POST['skype'];
$comments = $_POST['comments'];
$formerrors = false;
if ($name === '') :
$err_name = '<div class="error">Sorry, your name is a required field</div>';
endif; // input field empty
if ($email === '') :
$err_email = '<div class="error">Sorry, your email is a required field</div>';
endif; // input field empty
if (isset($_POST['comments'])) {
$comments = filter_var($_POST['comments'], FILTER_SANITIZE_STRING );
}
$formdata = array (
'name' => $name,
'email' => $email,
'fictioninterest' => $fictioninterest,
'bookclub' => $bookclub,
'newsletter' => $newsletter,
'blogtalk' => $blogtalk,
'skype' => $skype
);
if (!($formerrors)) :
$to = "bookclub@literaryfictionreview.com";
$subject = "From $name -- Signup Page";
$message = json_encode($formdata);
$replyto = "From: bookclub@literaryfictionreview.com \r\n".
"Reply-To: bookclub@literaryfictionreview.com \r\n";
if (mail($to, $subject, $message)):
$msg = "";
redirect_to("confirmation.html");
else:
$msg = "Problem sending the message";
endif; // mail form data
endif; // check for form errors
endif; //form submitted
?>
Do I need to take out the $msg = ""; line? And remove also the $msg line below that returns "Problem sending the message"; ? And I would need to put in a header tag?
Thanks so much for your help with this!
Send an HTTP "location" header ( http://en.wikipedia.org/wiki/HTTP_location ) via the PHP header()
function, eg header("Location: /foo.php");
You'll likely also want to subsequently exit()
the script so that actions below your if
conditional don't execute.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.