On Wednesday, March 20, 2002, at 11:57  AM, David Johansen wrote:

> I was just wondering what was the best way to handle a multipage form. 
> Would
> the best way be to keep passing the variables through the forms as 
> hidden
> values or should I use sessions and store all the values as session
> variables? What's the best way to handle all of this? Also the different
> forms will all be in the same php file that loops to itself if that 
> makes a
> difference. Thanks,

These can be a pain in the ASS.  But as for the answer to your question, 
it's really more a matter of personal preference and the particular 
application you have.  For instance, if I were writing a shopping cart 
or some extremely complicated sequence of forms that fork off into a 
tree-like structure, I'd probably just give up on hidden form fields and 
use session variables.  But because session variables can be tricky to 
unset (you have to make sure the user explicitly executes a script to 
unset them), I try to avoid it when I can.  I have a linear multi-part 
form (not one that branches into different directions) where I take user 
input and throw it all into hidden form fields -- very tedious, yes, but 
I have finer control over what values get passed around as the user 
moves on.

Side note: the trickiest thing can be getting multiple-listbox values to 
be passed on, since it'll be hard to put multiple values into a single 
form field.  The way to do it is a miniature loop for each case where 
you need to do this, that places each value into an element of an 
array -- then implode the array into a string and put the string into 
the hidden form field.  Explode the string back into an array on the 
next part of the form.

For a branching, tree-like system I'd probably use sessions unless for 
some reason you can't -- just make sure the user has a way of knowing 
what's "in their cart" (or equivalent for your site) somewhere, so that 
if they closed the window in the middle of filling out the form, 
possibly expecting it to reset all of their work, then they won't be 
surprised when they try to fill out the same form later and see all of 
their old values from their session.

Good luck


Erik



----

Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to