designing source code for multiple forms

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I want to start writing a new site. It will include 3 forms that will
collect information from the user. I know how to keep the info in
sessions etc. my question is about the design of the server side php
files. I don't want to design all three forms in one big file, id
rather have a separate php file for each form.

Say I have a file form1.php which creates the initial form, should I
say (form1 action="form1.php") and have the form validation code in
form1.php? If so how do I call form2.php from inside form1.php? Or do I
say(form1 action ="form2.php") and have my validation code for form 1
inside form2.php if so how do I call back form1 if validation fails

now this has been asked already (see link below)and it was suggested to
use the include() require() functions. but then others have argued
against it. so is includeonce() the most practical way or should I
rather write all the code in to one big index.php

Re: designing source code for multiple forms

Quoted text here. Click to load it

sorry i forgot to include the link, here you go +design+multiple+forms&_done=%2Fgroup%2Fcomp.lang.php%2Fsearch%3Fq%3Dphp+design+multiple+forms%26&_doneTitle=Back+to+Search&&d

Re: designing source code for multiple forms

I can't think of a good reason for either case -- wether you have
separate files for each section, or have one big file. That's why I'd
say it's more of stylistic issue.

That said, I'd argue for multiple pages, because, to me, it fits in
better with the logical flow of what you want to do. Like another guy
said in that old thread - I like the one-to-one correlation between
script and URL.

I typically have my form validation on the same page. Here's a sketch of
what I'm thinking. In form1.php:


// if it's valid submitted data, go to step 2
if (isValid())

<form action="form1.php" method="POST">
<!--- the form elements -->

....then in form2.php you could store the passed variables in a <input
type="hidden"> fields.

...then if you have problems, and the user has to go back to form1.php
you have those form1 varaiables tracked.

It sounds like you want to avoid passing everything around? I guess you
could use sessions, as you mentioned or, cookies. says...
Quoted text here. Click to load it

Site Timeline