Reputation:
Ok, so I would like to redirect to a thank you page after completion of my contact form. Right now, it's just a plain, unstyled thank you, and I would like it to redirect to a page that I've desiged called contact-thank-you.html
Here is my HTML form:
<form action="form_processor.php" method="post" >
Name:<br /><input type="text" name="name" required="required" /><br /><br />
E-mail:<br /><input type="text" name="email" required="required" /><br /><br />
Message:<br /><textarea name="message" required="required"></textarea><br /><br />
<input type="submit" value="Submit">
</form>
and here is form_processor.php:
$to = '[email protected]';
$subject = "New Message From Your Website";
$message = $_POST['message'];
$headers = 'From: ' . $_POST['name'] . ' <[email protected]>' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo "Thank you, you message has been sent!";
Upvotes: 2
Views: 39056
Reputation: 10623
If you want to redirect from html page to another page like php page then just write this code it will work for you
<?php
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
//or
header( 'Location: nextpage.php' ) ;
?>
Upvotes: 1
Reputation: 11
header('Location: thank-you.php');
or u can echo massage (ajax message on same place)
if(@mail($address, $e_subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
{
echo "<p class='ajax_success'>Thanks for Contact Us.</p>";
}
else
{
echo "<p class='ajax_failure'>Sorry, Try again Later.</p>";
}
and here ajax validation;
jQuery.noConflict();
jQuery(document).ready(function ($) {
//Main Contact Form...
jQuery("#frmcontact").validate(
{
//Onblur Validation...
onfocusout: function(element)
{
$(element).valid();
},
rules:
{
txtname:
{
required: true,
minlength: 5
},
txtemail:
{
required: true,
email: true
},
txtphone:
{
required: true,
minlength: 5
},
txtenquiry:
{
required: true,
minlength: 10
}
}
});
//Ajax Submit...
$('#frmcontact').submit(function () {
if($('#txtname').is('.valid') && $('#txtemail').is('.valid') && $('#txtphone').is('.valid') && $('#txtenquiry').is('.valid')) {
var action = $(this).attr('action');
$("#ajax_message").slideUp(750, function () {
$('#ajax_message').hide();
$.post(action, {
name: $('#txtname').val(),
email: $('#txtemail').val(),
phone: $('#txtphone').val(),
comment: $('#txtenquiry').val()
}, function (data) {
document.getElementById('ajax_message').innerHTML = data;
$('#ajax_message').slideDown('slow');
if (data.match('success') != null) $('#frmcontact').slideUp('slow');
});
});
}
return false;
});
and lucks very good
Upvotes: 0
Reputation: 2713
remove echo "Thank you, you message has been sent!";
because it won`t be necessary to have it since your redirecting your page then use this after all the transaction in finish to redirect
header('Location: contact-thank-you.html');
exit();
And Create a nice Thank You Template on you contact-thank-you.html
Resources:
php.net: header()
Upvotes: 10
Reputation: 26
header('Location: contact-thank-you.html');
This should be the answer that you are looking for(:
You can refer to here: http://www.cyberciti.biz/faq/php-redirect/
Upvotes: 0
Reputation: 219834
replace:
echo "Thank you, you message has been sent!";
with:
header('Location: contact-thank-you.html');
exit;
reference
Upvotes: 4