Page 1 of 1
Form processing decisions
Posted: Sun Jul 20, 2008 8:20 pm
by Pandu
I'm new to PHP and as such, I don't know the conventions in the designs. An example is the processing of forms. Are you supposed to feed all of the form info back into the form page, or are you supposed to have a new page saying something like "Thanks for filling the form out."?
You could implement it both ways. The first way saves you having to create a whole new file to handle successful requests, but you create more cluttered code.
Which way do you do it, and which way is the most used?
Re: Form processing decisions
Posted: Sun Jul 20, 2008 8:36 pm
by califdon
Ask ten programmers and you will probably get a dozen answers. Seriously, there probably are some best practices, but for myself, it depends on how complex the script will be. If I can use the same script with several conditional branches, and it doesn't become really heavy, I will opt for one script, to keep it all together. But if that makes it a huge script that's hard to maintain, I will factor it into several scripts. Probably the use of OOP and include files would improve the way I code, but I haven't gotten very far into OOP, as yet.
Re: Form processing decisions
Posted: Sun Jul 20, 2008 9:08 pm
by Christopher
Post to yourself; redirect to the "thank you" page. That keeps the code in one place for dealing with errors, and the redirect eliminates the "refresh resubmits the form" problem.
Re: Form processing decisions
Posted: Sun Jul 20, 2008 11:41 pm
by omniuni
arborint, that is a brilliant way to fix the whole refresh problem.
I need to remember that.
Why the heck didn't I think of that....
Re: Form processing decisions
Posted: Mon Jul 21, 2008 12:54 pm
by inghamn
Does that also fix the resubmit if the user clicks on the back button? I've still got that problem in all my forms.
Re: Form processing decisions
Posted: Mon Jul 21, 2008 1:03 pm
by Christopher
To solve that you may want to set/regerate a session variable on the "thank you" page that tells the form page that it has already been processed. This could also be part of generating a unique ID and passing it to validate the from submission.
Re: Form processing decisions
Posted: Tue Jul 22, 2008 12:23 am
by VirtuosiMedia
This may or may not answer your question, but for some general form best practices, you might want to consider downloading the slides on
this page and reading
this post.