forms and form handler, multiple pages or one?

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
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

forms and form handler, multiple pages or one?

Post by josh »

When you have a simple form, let's say a contact us form do you usually:

A) Make 2 pages, one with the html form and another page to handle the form data

or

B) Keep it in one page, output a hidden value into the html form, upon loading of this page we check if the hidden value has been set, if not we output the html form, if the hidden value has been set we run the portion of the code that handles the form.



What about multipart forms?

Do you tend to have:
A) form1.php form2.php form3.php form_handler.php

or do you tend to go with the:
B) form.php?part=1 form.php?part=2 form.php?part=3 form.php?part=process?
(but with post variables of course)

I usually opt for option B especially with multipart forms, just so I don't have a huge amount of php scripts sitting around. The only time I opt for A is when the form handler calls for very large amounts of code, it's just easier to have it in it's own file in some cases.

Share your methods / opinions
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

All my forms submit to themselves, and check a hidden variable to see if they should handle the form input. Multipart forms do the same, and use header("Location: part2.php") type things to travel from one section to the next. It's just the way I've always done things, it encapsulates everything for each form in a single script.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

There are some good comments on this here:
viewtopic.php?t=9775

Looking at bout 4 different form handling models.
Post Reply