Yii Framework Forum: Stateful Forms and Wizards -- Howto? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Stateful Forms and Wizards -- Howto? Rate Topic: -----

#1 User is offline   gsatir 

  • Junior Member
  • Pip
  • Yii
  • Group: Validating
  • Posts: 28
  • Joined: 21-April 09
  • Location:Portland, OR

Posted 18 December 2009 - 11:12 PM

Hi, All

I have an employee-tracking app that needs to be able to take basic information (name, address, etc.) from a prefilled Excel sheet. I'll need to turn the one sheet into information in a few tables once the user uploads it and answers some questions. In short, I'll need a wizard for importing csv data.

It looks like Stateful Forms were created for this purpose. I cannot find any information about how to implement a wizard with Stateful Forms. Can anyone orient me a bit? Thanks in advance.

Greg
0

#2 User is offline   cmx 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 21-November 09
  • Location:California USA

Posted 20 December 2009 - 06:44 PM

Quentin Zervaas has a tutorial on writing multi-part forms (e.g., property sheets) and wizards on his phpriot site.

http://www.phpriot.c...ti-step-wizards

I used the above for several technical support troubleshooing guides a few years ago and it worked out fairly well.
0

#3 User is offline   gsatir 

  • Junior Member
  • Pip
  • Yii
  • Group: Validating
  • Posts: 28
  • Joined: 21-April 09
  • Location:Portland, OR

Posted 21 December 2009 - 07:32 PM

Thanks, cms, that's a useful pointer for making a wizard in php. I'll also add that the hangman demo uses Stateful Forms, and is the best example in Yii of their use that I could find. If anyone else has more about Yii, stateful forms, and wizards, I would still love to get more pointers.

best wishes,

Greg
0

#4 User is offline   Seal 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 02-February 10

Posted 12 March 2010 - 05:36 PM

View Postgsatir, on 21 December 2009 - 07:32 PM, said:

Thanks, cms, that's a useful pointer for making a wizard in php. I'll also add that the hangman demo uses Stateful Forms, and is the best example in Yii of their use that I could find. If anyone else has more about Yii, stateful forms, and wizards, I would still love to get more pointers.

best wishes,

Greg


Hi I have similar challenges right now. Which solution did you manage to go with within yii framework?
Sylvester La-Tunje

Posted Image
0

#5 User is offline   gsatir 

  • Junior Member
  • Pip
  • Yii
  • Group: Validating
  • Posts: 28
  • Joined: 21-April 09
  • Location:Portland, OR

Posted 12 March 2010 - 07:30 PM

Hi, Seal

There are a couple of pieces that need to be put into place for it to all work. I will outline my understanding and you can ask me questions if it's not detailed enough. The basic idea to start with is that a wizard needs multiple pages sharing information to work. So this information needs to be passed from the page to the controller to the next page to the controller to the next page, etc.

Starting with the controller, whatever you want passed along, you need to store in the controller using setPageState(). This creates an entry in a private associative array in the controller with the key and value that you pass.

The values set in the controller with setPageState() are automatically stored in a view containing a StatefulForm. Each page of your wizard (except maybe the first and the last) needs to have a StatefulForm on it. This will create a hidden value called YII_PAGE_STATE that has an encoded copy of all the values set in the controller. The controller that gets the POST of a page with a StatefulForm will then be able to retrieve the values with getPageState(). Each page will also have fields of data that get filled in and POSTed as usual (in addition to the YII_PAGE_STATE) andthe controller processes these and adds what it needs to the page stateto be passed down the line.

To summarize, values get POSTED from a page, set in the controller with setPageState(), get passed to the next page with a StatefulForm, and retrieved in the controller with getPageState(). It goes: page to controller to page to controller to page to controller, etc. and you can have as many pages as you want sharing data.

The only effect making a wizard had on the model was that I didn't use many models. My first page took scalar information about the file to upload, the number of lines to read, etc. I had a FormModel for data validation. My other pages showed the table to import and allowed the user to edit the fields. There was not much use for FormModel's for these pages, so the controller did the validation work here.

It was kind of a fat-controller approach. Besides not using models much, I had a single ImportController that took control each time a page of the wizard was passed back. It handled everything, with a bit of help from the one FormModel mentioned above and a view for each page of the wizard.

That's all I can think of for now. Hope this helps.

Greg
0

#6 User is offline   Seal 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 02-February 10

Posted 15 March 2010 - 01:33 PM

View Postgsatir, on 12 March 2010 - 07:30 PM, said:

Hi, Seal

There are a couple of pieces that need to be put into place for it to all work. I will outline my understanding and you can ask me questions if it's not detailed enough. The basic idea to start with is that a wizard needs multiple pages sharing information to work. So this information needs to be passed from the page to the controller to the next page to the controller to the next page, etc.

Starting with the controller, whatever you want passed along, you need to store in the controller using setPageState(). This creates an entry in a private associative array in the controller with the key and value that you pass.

The values set in the controller with setPageState() are automatically stored in a view containing a StatefulForm. Each page of your wizard (except maybe the first and the last) needs to have a StatefulForm on it. This will create a hidden value called YII_PAGE_STATE that has an encoded copy of all the values set in the controller. The controller that gets the POST of a page with a StatefulForm will then be able to retrieve the values with getPageState(). Each page will also have fields of data that get filled in and POSTed as usual (in addition to the YII_PAGE_STATE) andthe controller processes these and adds what it needs to the page stateto be passed down the line.

To summarize, values get POSTED from a page, set in the controller with setPageState(), get passed to the next page with a StatefulForm, and retrieved in the controller with getPageState(). It goes: page to controller to page to controller to page to controller, etc. and you can have as many pages as you want sharing data.

The only effect making a wizard had on the model was that I didn't use many models. My first page took scalar information about the file to upload, the number of lines to read, etc. I had a FormModel for data validation. My other pages showed the table to import and allowed the user to edit the fields. There was not much use for FormModel's for these pages, so the controller did the validation work here.

It was kind of a fat-controller approach. Besides not using models much, I had a single ImportController that took control each time a page of the wizard was passed back. It handled everything, with a bit of help from the one FormModel mentioned above and a view for each page of the wizard.

That's all I can think of for now. Hope this helps.

Greg


Hi Greg,

Thank you indeed for this info. I will try it out and get back to you in 48 hours...
Sylvester La-Tunje

Posted Image
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users