Form processing decisions

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Pandu
Forum Newbie
Posts: 1
Joined: Sun Jul 20, 2008 8:13 pm

Form processing decisions

Post 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?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Form processing decisions

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Form processing decisions

Post 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.
(#10850)
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Form processing decisions

Post by omniuni »

arborint, that is a brilliant way to fix the whole refresh problem. 8O

I need to remember that.

Why the heck didn't I think of that....
User avatar
inghamn
Forum Contributor
Posts: 174
Joined: Mon Apr 16, 2007 10:33 am
Location: Bloomington, IN, USA

Re: Form processing decisions

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Form processing decisions

Post 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.
(#10850)
User avatar
VirtuosiMedia
Forum Contributor
Posts: 133
Joined: Thu Jun 12, 2008 6:16 pm

Re: Form processing decisions

Post 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.
Post Reply