Portal Home > Knowledgebase > Articles Database > Form Processing in PHP
Form Processing in PHP
Posted by techdude20078, 01-02-2010, 12:43 AM |
I have a form that needs to be processed (user information stored in database and emailed to the contact email), however I want to prevent the user from reloading the "Thank You Page" (which currently processes the form) which would therefore add the information to the database again and resent the email again. I thought about placing a php page in-between the form and the thank you page and stick a loading gif in the form, but then that would add content to the form and prevent me from having a header(Location: myurl.php);. How else could I forward a "loading/processing" page to a thank you page? Or any other ideas of how to complete this?
|
Posted by e-Sensibility, 01-02-2010, 12:46 AM |
javascript+ajax is what you're looking for. It has to be done on the client-side, i.e. in the browser, to avoid the intermediary page. Google around and I'm sure you'll be able to find something copy/paste-able
|
Posted by hostizzy, 01-04-2010, 10:46 PM |
You could try using redirects in the form?
eg
if ($action == "form") {
FORM IN HERE
}
elseif ($action == "data) {
MYSQL_QUERY HERE
}
elseif ($action == "thankyou") {
THANK YOU MESSAGE HERE
}
You just need to make sure it automatically directs. If you want a full example of what I mean, then just let me know and I'll write you out a full example code form.
|
Posted by Jatinder, 01-05-2010, 01:26 AM |
Simplest solution:
form.php
Your form. Submits to form-exec.php
form-exec.php
//Validation code
//Send out email
header('Location: thank-you.php');
thank-you.php
Thank you for contacting us....
If you want to display "Processing..." message on form-exec.php page, use Javascript redirect instead of PHP redirect.
|
Posted by Krupux, 01-06-2010, 09:56 AM |
Yes, Jatinder just described what is known as PRG pattern:
http://en.wikipedia.org/wiki/Post/Redirect/Get
However, for me, if you really want to display a "Processing..." message, I would do it in form.php instead (i.e. maybe with onclick="showProcessingDiv();" on the Submit button)
|
Posted by mattle, 01-06-2010, 11:43 AM |
Thanks for the link! I've used the concept a million times, but had no idea it was formalized!
|
Add to Favourites Print this Article
Also Read
geoip (Views: 745)