I’m trying to stay on the current page from where a form gets submitted. But somehow it’s not working. I found some peaces of code on the internet and put it together.
This is the process.php file:
<?php
// Get Data
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$subject = strip_tags($_POST['subject']);
$message = strip_tags($_POST['message']);
// Send Message
mail( "email@domain.com", "Contact Form testttt",
"Name: $name\nEmail: $email\nPhone: $phone\nWebsite: $url\nMessage: $message\n",
"From: Forms testtttttttt" );
?>
And the rest of the code, the html and javascripts can be found on jsfiddle:
jsfiddled code
$(function(){
$('#contact').validate({
submitHandler: function(form) {
$(form).ajaxSubmit({
url: 'process.php',
success: function() {
$('#contact').hide();
$('#contact-form').append("<p class='thanks'>thanks test.</p>")
}
});
}
});
});
Forgot to mention what happens now. I get redirected to process.php page.
Use jQuery.ajax() function to submit a form without refreshing a page. You need to do something like this:
test.php:
process.php:
ajaxform.js