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?
Form processing decisions
Moderator: General Moderators
Re: Form processing decisions
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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Form processing decisions
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.
(#10850)
Re: Form processing decisions
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....
I need to remember that.
Why the heck didn't I think of that....
- inghamn
- Forum Contributor
- Posts: 174
- Joined: Mon Apr 16, 2007 10:33 am
- Location: Bloomington, IN, USA
Re: Form processing decisions
Does that also fix the resubmit if the user clicks on the back button? I've still got that problem in all my forms.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Form processing decisions
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.
(#10850)
- VirtuosiMedia
- Forum Contributor
- Posts: 133
- Joined: Thu Jun 12, 2008 6:16 pm