Welcome Guest, Not a member yet? Register   Sign In
Multi Page Form Logic
#1

[eluser]Jesse Schutt[/eluser]
Anyone care to share how they code a "Multi Page Form"? I am working on a registration form that I would like to span over several pages, or steps.

Thanks Much!

Jesse
#2

[eluser]TheFuzzy0ne[/eluser]
If I were taking the same approach as you, I would validate each page, and insert data into the database there and then. This would mean grouping all dependencies on a single page, for example, username, password, email address on one page, non-essential information, such as contact information on the next, things about likes, dislikes, hobbies etc... on the page after

If all of the data is dependant on eachother, then I think the only way to do it would be to dump the data into a table for holding temporary data.
#3

[eluser]Jesse Schutt[/eluser]
So, in essence you are suggesting that I treat it as several different forms that could be independent of each other?
#4

[eluser]TheFuzzy0ne[/eluser]
I'm just saying that that's most likely the way I'd do it. It doesn't mean it's the right way, and it would depend on exactly what kind of data I was trying to obtain. There are probably many other ways to do it, but my first instinct is never to trust the user with data you're dependant upon, which is why I would avoid cookies. If you did use userdata or hidden inputs, the data could probably be changed by the user, and would need to be revalidated again at the end. Granted, most users wouldn't have a clue how to change it, but there are those few whose life ambition seems to be to destroy other people's work.

I also have two more ideas that could work for you:

The form could be on a single page, and you could use some JavaScript magic to give the illusion of several instantly loading pages.

My other idea (which was pinched from Derek Allard) align the pages side by side, and have them slide into view. I don't know what the technique is called, but I noticed it when using Derek Allard's BambooInvoice with JavaScript disabled (yes, I was trying to catch him out and was ). I thought it was quite neat. Try disabling JavaScript and then going to http://www.bambooinvoice.org/index.php/settings. Try clicking on Invoice Settings and Advanced Settings. It feels almost Ajaxy, only without the Ajax...

I just thought I'd give you my two cents. Smile
#5

[eluser]Sarfaraz Momin[/eluser]
I have done multiple form a few times. I started off with saving formfields from previous form in hidden field of the next form and have sensitive data like username and password on the last form before submitting it to the database. Validation is done on every page. Then I also did Ajax forms which imitates multiple forms being in the same window I used sessions in for it. I also did a normal multi step form with sessions and it seems to work good.
I would see if I can share some code with you.

Have a good day !!!
#6

[eluser]Jesse Schutt[/eluser]
Thanks for the thoughts. I really appreciate you taking the time!

Jesse
#7

[eluser]Jesse Schutt[/eluser]
Sarfaraz,

I would love to see some code :-)

Jesse
#8

[eluser]Jesse Schutt[/eluser]
Just out of curiosity, how would you structure the controller and form? Do I need a different function for each page of the form? Or, is it one function that walks through all of the pages?

Code:
Controller:

function part_1() {
  if(validation == false)
  {
     load a view
  }
  else
  {
     process input
     send to db
     ???????Move to another function?????
  }
}

And in the form, I am a little confused as where to send that action="" parameter...

Any help would be appreciated.

Jesse
#9

[eluser]TheFuzzy0ne[/eluser]
It's your call. You could have a different method for each, after all they are technically different forms and different pages. You could also put the logic into a single method, but you might find it gets a bit big. With that said, any logic to tell which page is which will probably be minimal, so you should only end up with slightly more code than you would have had, had you processed the form in a single transaction.

I guess the question is, what other methods will your controller have? If it's a controller specifically dedicated to that set of forms, I would use a method for each. If the controller handles other things, I'd probably go for everything in a single controller method, and perhaps use a switch case. Again, it's really up to you, and how you'd prefer your code to be. I don't think there's any "typical" way to do it.

About the action parameter; can you be more specific?
#10

[eluser]Jesse Schutt[/eluser]
Again, thanks for your response!

The controller is only for processing the form, so I think I will try to have a specific function for each page of the form. Give me a bit and I'll post some code...

Thanks!

Jesse




Theme © iAndrew 2016 - Forum software by © MyBB