I used response.redirect in asp to avoid form re-submit, so I can have form handling functions and other related functions on the same file.
new_customer_form.php : < form action="form_results.php" >
Customer fills form and hits submit button.
form_results.php : function validate_form_data(){ if true show_results(); } function show_results() {...}
Now customer is on results page in show_results(). If he hits the Refresh button or Back then Forward buttons in he will be prompt to resubmit the form data or cancel. If I add header("Location: form_results.php") inside function validate_form_data() instead of calling function show_results() I can avoid this behaviour.
I don't know if this is the right procedure, i am learning as I develop. This was a workaround for shopping cart and customer area form handling form handling code. Probably I'm doing it all wrong :)
Yeah, this is a good method for a lot of form processing. It's as simple as having the processing/validating in one area and the form/error display in another. Once the form is accepted/rejected, you just header() redirect to the form or error page. Too easy and it prevents a lot of confusion for your users.
And Robby thanks for the ob_start() tip!
This is a workaround, really. Your code should be structured so that you can decide if you need to perform a redirect before any output is sent to the browser. If you're going to send them to another page, why would you have any output anyhow? Using templates sometimes forces you to do this, as you perform all of your business logic / PHP code before hand and then display the appropriate templates. If you need to send the user to another page, it's easy to do so at any point before your templates are shown.
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php