Submitting forms

Associate
Joined
30 Nov 2003
Posts
1,614
So currently I have a little contact form made in HTML. At the moment when the submit button is hit it forwards to another page where it is sent by PHP, a thank you message is displayed and then that page redirects back to the form again.

Is there a better way of doing it so that the form can submit the email and then on that same page a message be displayed to say thank you? Maybe a bit of jQuery?
 
Is there a better way of doing it so that the form can submit the email and then on that same page a message be displayed to say thank you? Maybe a bit of jQuery?

You could do the whole thing using a .php file that posts back to itself. That way you can display any message on the same page without having to redirect. You'll need code to validate the whole form before the send mail functionality can run.

Rgds
 
jquery can do this nice and easily but you need to learn how to use juqery first if you hasven't. bascially what jquery will do is watch for when the submit button is clicked, then if it has it'll gather the information from the fields, submit it to the same page you've sent it to before, then check the response and let the user know.
 
FormPage.php

<form method="post" action="FormPage.php">
</form>

<?php
if ($_SERVER['REQUEST_METHOD'] = 'POST') { // If form is submitted
Do/Show This
} else {
Do/Show This
}
?>


Keep in mind you only show the form if the page request isn't submitted. So form goes in the "else" part.

This should get you started.

mail();
header();

etc... may with to throw in some conditionals to make sure the form doesn't fail. All filled out etc.
 
Back
Top Bottom