Reputation: 43
This is my site that I'm working on the contact page.
I'm using formmail.php for the contact form (http://www.tectite.com/)
When the user submits the form I want it to say something like "Thank you, your message has been sent." But I want this text to be displayed on the page where the form is - NOT open a separate URL.
There is already a way to redirect to a separate page by using:
<input type="hidden" name="good_url" value="http://yoursite.com/thanks.htm" />
However since my site is a single page scrolling site, I want to avoid navigating away.
Upvotes: 3
Views: 234
Reputation: 135
Try this ajax
$.ajax({
type: "POST",
url: "send.php",
data: $(form).serialize(),
timeout: 3000,
success: function() {
$("#contactForm").hide();
$('#divContactFrm').html("<div id='divSuccessMsg'></div>");
$('#divSuccessMsg').html("Thank you!")
.hide()
.fadeIn(1500, function() { $('#divSuccessMsg');
});
}
Upvotes: 0
Reputation: 628
You can use Ajax as @Abhishek answered. Or do something like below.
if(isset($_POST['submit']))
{
//Your code for mailing
header('location:formmail.php?message=set');
}
Then at the place you want to show the message
if(isset($message))
{
echo "Thanks";
}
Upvotes: -2
Reputation: 4651
You can simply use ajax functionality to do it
$.ajax({
url: "page which you want to call on action",
data: $( "form" ).serialize(),
type: 'POST',
async: false,
success: function(responseObject) {
// $("#hiddendiv").show(); // OR
// $("#hiddendiv").html("thanks message");
}
});
Upvotes: 3