I have been going crazy for two hours trying to get this to work. I have a form, it works fine. After I submit the form, I want to display a success message and hide the form. Right now, after pushing the submit button, the form goes away, the success message displays for the blink of an eye and then the contact page shows normally. That is all fine, I just need the success message to stay up a bit longer.
$contactName = strip_tags($_POST['contactname']); $subject = strip_tags($_POST['subject']); $email = $_POST['email']; $messages = strip_tags($_POST['message']); //check to see if the variables are empty, if they are, just exit $validation = true;
Using jQuery to display a success message is a bad design as how does your client side code know if the email was sent successfully?
What you need to be doing is using your PHP script to validate the data and check if the email got sent successfully and display a message based on the result.
I am using the php to check that it got sent. then I am putting in some jquery to display the success message. I disagree with you that it is bad design as php works very well with html and javascript mixed. Also this is pretty much an accepted practice.
The jqyery to run the success message is at the bottom of the code
You might wanna check your message before displaying the success message.
What you need to be doing is using your PHP script to validate the data and check if the email got sent successfully and display a message based on the result.