I have a simple PHP contact form on my website that I’m building. At the moment when the form is submitted the page refreshes then using PHP displays a success message underneath the cleared contact form.
Is there any way I can have the page NOT refresh and still display the PHP success message via Ajax and how can I do this?
I’m very new to PHP. Here’s part of my current code…
if ($nr != $sum)
header('Location: index.php?msg=wrong#contactform');
else
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");
// redirect to success page
if ($success){
header('Location: index.php?msg=sent#contactform');
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
}
You might find this helpful. It’s a query plugin to easily make a form ajax submit. http://malsup.com/jquery/form/