Welcome Guest, Not a member yet? Register   Sign In
How to exchange user data with the same class instance
#3

When I do a multi step form process like you are describing (and I presume you are not using ajax) I change the url of the form action depending on the step like:

PHP Code:
<?php echo form_open('the_controller/the_method/'.$step); ?>
Where the step is step_1 or step_2 etc.

The controller then looks at this value, if not set it issues step_1, if set it does form_validation for step_1, which if passed, then sets the step to step_2 etc.

I store the values of the various steps usually in the session. I also for step_2, say, check that the session info is set for step_1, so I do not just trust the url in the form (as a user might have changed it manually). If on step_4 the session variables are not set for say step_2, I would show step_2.

If it is a very big form, or a form that needs to be persistent, like billing address and delivery address, I store the info in a database table linked to the user. If the user half fills out the form, then leaves, then logs in again, going to the form automatically loads the info already set for the step.

This works particularly well for checkouts.

For a one page checkout and ajax I put the step in a hidden field. Then the ajax return either returns error fields or the new form body for the next step. This is nice but is a bit more complex than doing page loads.

The only alternative I know of is javascript multi step forms, where the next button hides the current step and shows the next step, or reveals the next tab, but in affect it is just one giant form, just with some display trickery. I am not keen on this as options set in step_2 for instance can mean step_3 is missed out, or info or further options change depending on the previous choices. This all gets complicated in a single form solution.

So to answer your question, I think a step indicator (in url or hidden field) with data stored in session until step process is completed or confirmed, is the best solution.

Coded cleanly and carefully, it can also be quite clear what is happening and easy to debug too.

Hope that helps,

Paul.
Reply


Messages In This Thread
RE: How to exchange user data with the same class instance - by PaulD - 11-27-2017, 02:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB