Multipage Forms

Hello,

does anybody have an example of how to create a dynamical multipage form with Yii?

What I need is a form which is divided into multiple pages.

Based on the user’s answers in each step the options available in the next step should be determined.

Example:

In a shopping application the user can enter his address data and choose a payment method on page 1 and then proceed to page 2 of the form. On page 2 he has either to enter his credit card information or his bank account data, based on the payment method he has chosen in step 1.

If no example of such a "dynamic" mulipage form is available, maybe someone has an example of a static mupltipage form, so a single static form which is divided into multiple pages?

Regards,

Iggi

Hi, I have no example but a hint. You can create OrderForm model. In there you can define a scenario for each page. When the user submits for example page 1, you save the whole form in session and proceed to page 2. After the last page got submitted, you can access each scenario input from session for processing. Also it should be easy possible to implement a back-button so customer can recheck input.

Thanks a lot for your hint. I will give it a try. Nevertheless - if anybody has an working example, I would appreciate.

Regards,

Iggi

Read about persisting form state (hangman game demo).

@ Iggy, I’m facing the same challenge right now…Did you manage to come up with a solution for a multi page forms?

Regards

Seal

Hi Iggi ,

could u realize like this .

step1: setup a var to save ur selected option

step2: has different divs, and display a <div> based on ur step1’s option, use one form to submit is ok.

and then the step3: u can get desired data base on ur rule.

u can refer to the worldnumbers.com to refer it, there our payment selection in one page but same logic.

Since my datamodel is pretty complicated, with multiple relations among the tables

I am considering doing it like this and wondered what more experienced people thought.

  1. create arrays to store the form fields in - in the Model(?)

  2. Each page of the form consists of one or more widgets which extend cActiveForm

  3. Each Widget recieves Ajax validation

  4. On Validation, the fields are saved to instances of the arrays mentioned in step 1.

  5. on form completion the content of the areas are saved to the database. (I think I need to save some parent tables first for ref. integrity reasons.

Thanks