Yii Framework Forum

Wizard Behavior


(Dave Mcnair) #21

Hi

nice extension thanks!

Have used it successfully for a multi-step scenario via actionCreate($step)

Having trouble with update scenario though - getting from actionUpdate($id) to actionUpdate($step) doesnt fit…

How in such cases do I handle repeated calls to the a wizard action when I need to pass parameters to the first step?


(Chris) #22

The wizard must only go through one action, e.g. actionWizard($step). Step and wizard completion processing is done in event handlers.

If you want to pass additional parameters you can do something like:




public function actionWizard($step=null, $p1=null, $p2=null) {

  if (is_null($step)) {  // only at the wizard start

    $session = Yii::app()->getSession();


    foreach(array(p1,p2) as $p) {

      if (!is_null($$p)) {

        $session[$p] = $$p; // save the parameter to the session

      }

    }

  }

  $this->processStep($step);

}



Then your event handlers can use the parameters saved in the session as required.


(Renate Vidruska) #23

Hi!

Seems to be nice wizard, but as I am new to YII, I have a problem:

I have the following code (simply two steps, currently i need only next button and when wizard finishes i need to display ‘finished’). My code:





  public function myWizardProcessStep($event) {				

	$data = array();		

	switch ($event->step) {

		case "contactData" : 

			$d['form'] = "_sp1form";

			$d['model'] = new Project();

			$data[] = $d;

			

			$d['form'] = "_contactform";

			$d['model'] = new Contact();			

			$data[] = $d;

			

			$d['form'] = "_addressform";

			$d['model'] = new Address();

			$data[] = $d;

			

                        //$d['model']->attributes = $event->data; //@todo: need to get data for multiple models - address, contact, project

						

			break;

		case "personData":			

			$d['form'] = "_personform";

			$d['model'] = new Person();

		

			$d['model']->attributes = $event->data;

			$data[] = $d;

			

			break;

	}

	

	if (isset($_POST['step_name']) && $_POST['step_name'] == "contactData")

	{

		$event->handled = true;

	}

	if (isset($_POST['step_name']) && $_POST['step_name'] == "personData")

	{

		$event->handled = true;

	}

		

      $this->render('wizardForm', 

		array(	'event'=>$event

				, 'data'=>$data

			));   

  }



My view:




<?php

	echo $event->sender->menu->run();

	echo '<div>Step '.$event->sender->currentStep.' of '.$event->sender->stepCount;

	echo '<h3>'.$event->sender->getStepLabel($event->step).'</h3></div>';

?>

  

 

<div class="form">

	<?php $form = $this->beginWidget('GxActiveForm', array(

		'id' => $event->step.'-form',

		'enableAjaxValidation' => true,

	));

	?>


	<?php echo CHtml::hiddenField('step_name', $event->step);?>	

	

<?php	

	if (isset($data) && !empty($data))

	{

		foreach ($data as $key=>$d)

		{

			echo $form->errorSummary($d['model']);

			$this->renderPartial($d['form'], array(

				'model' => $d['model']

				,'form'=>$form

			));

		}

	}			

?>




<?php


echo CHtml::htmlButton(Yii::t('app', 'Next'), array('class' => 'button', 'type' => 'submit', 'name'=>'next'));

		




$this->endWidget();

?>

</div><!-- form -->




Doesn’t work. I guess that trying to check $_POST[‘step_name’] is not correct way. I am stuck.


(Russell) #24

Hi

How do I skip a step, but set the form value?

Example.

Step 1:

Do you have a favourite colour? Yes/No

Step 2:

Yes, I have a favourite colour… it’s […] <— prompt for input.

or

No Favourite colour? Okay, I’m gonna choose for you… Red!

Thanks

Russell


(Russell) #25

And another newbie question…

can I loop back to a previous step.

I want a wizard that says

Step 1. How many serial numbers do you want to enter […] <- e.g. user enters 10.

Step 2. Enter your serial number […]

Then it loops back to 2 again, doing so ten times.

Cheers

Russell


(Email) #26

Hey, thanks for this extension. I ran into one problem though.

You should make it clear in the docs that the onStart event is mandatory. Not specifying a handler for it will cause the error:


Fatal error: Call to a member function toArray() on a non-object in /projects/siteninja/dojo/app/protected/components/WizardBehavior.php on line 278

Actually, I think it shouldn’t be mandatory. Currently, I have a pointless method on my controller:




	public function wizardStart($event) {

		$event->handled = true;

	}



But hey, that’s just a minor detail. Congratulations!


(Chris) #27

In the processStep handler check to see if a colour has been given; if not allocate one. You can get the data for previous steps via the read($step) method; supply a step name to get data for that step only or leave empty to get data for all steps.


(Chris) #28

Put the handling of the two steps in the processStep event handler, and anything that should happen at the end in the finished event handler or in the controller/action pointed to by finishedUrl.


(Zanforlin) #29

I have a problem too.

My $event->data is always empty. On the finish of the wizard, I can see the fields of the forms from each step, but I cannot see the entered content.


	public function imovelWizardProcessStep($event) {

	

		$modelName = ucfirst($event->step);

		$model = new $modelName;

		//var_dump($_POST);

		$model->attributes = $event->data;


		if (isset($_POST["submit"])) {

 			$event->sender->save($model->attributes);

 			$event->handled = true;

 		}

		else{

			$this->render($event->step, compact('event','model'));

		}

	}



I have a model and a form outside the model, not like the example.

Does anybody know what´s happening?

Thanks

Leo


(Renate Vidruska) #30

How to skip one step from wizard? I do not have any branches, I need only to skip one step if some conditions happen. I need also everythink wokring when previous button is pressed (also skip given step if it was skipped before).


(W3sar) #31

Looks nice, great work.


(Joe) #32

Strange behavior …

I have implemented a simple a quiz-application with wizardbehavior. All works fine on my developer workstation (XAMPP Windows).

But when I deploy the project I get a 500 Internal Error on starting the quiz.

Other Yii-apps on the same server are working without problems.

The problem is the method getExpectedStep(), because the session contains a __PHP_Incomplete_Class:

var_dump($_SESSION); in WizardBehavior.getExpectedStep():

["Wizard.steps"]=> &object(__PHP_Incomplete_Class)#1 (5) { ["__PHP_Incomplete_Class_Name"]=> string(4) "CMap" …

Any ideas?

[SOLVED]

session.autostart was ON at the production server :frowning:

should be OFF


(Szfjozsef) #33

How do I add a Captcha to a page??

I tried to extend captcha to add missing properties but the image won’t show and validation gives fatal error.


(Rmandovnz) #34

OK, what a great ext :D , great to understand and well documented. anyone with ajax version?


(Idrini) #35

Thank you so much for showing the array_merge line:)


And what a killer extension. great job


(Yii) #36

Hi, I’m having an issue with the Plot Branching, I’m finding that my steps within the branch are getting lost. I believe they’re being overwritten by the steps after the branch. My steps are:




'steps' => array(

   'staffForm',

   array( 'customerSearch' => array( 'customerSearchForm', 'customerSearchResultForm' ) ),

   'customerForm',

   'documentationForm',

   'confirmationForm'

),

I’m using BRANCH_SELECT and BRANCH_DESELECT to enable or disable the customer search branch based on which path the user came into the wizard. However the resulting steps when enabled are:

[list=1]

[*]staffForm

[*]customerSearchForm

[*]customerForm

[*]documentationForm

[*]confirmationForm

[/list]

The customerSearchResultForm is missing. When doing some digging I found that _parseSteps did:


$parsed[$label] = $step;

Where $label is the index of the step, this means though that as the steps are built the following happens:

LOOP1: 0 => staffForm

LOOP2: 0 => staffForm, 1 => customerSearchForm, 2 => customerSearchResultForm

LOOP3: 0 => staffForm, 1 => customerSearchForm, 2 => customerForm

If I remove the $label from the $parsed[$label] = $step then it makes sure all new steps are always appended.

Am I just doing it wrong?


(Codesutras) #37

Hi Yeti ,

first of all I would like to give you thanks for such a nice extension. :) :)

Today,i was playing with extension and i got some question in my mind.On which i am still working.SO, it would be great if you can also dig into this problem and can share your thoughts for this.

Here is my problem :-

"I am Creating a multi step form to Add a Product with the help of this extension.But i have some questions in my mind.

  1. What about a Image Upload in the Step forms. ;) How to use a File type input element in the form.How to deal with it.

  2. How to use a Fckeditior Widget with Text Area input element.

And last One to get a better Idea from you.

  1. How to save a data After complete a form steps.

"

:) Kindly please help me here.i am waiting for your kind response. :)

Thanks in Advance !!


(Makro76) #38

Hi! Great extension!!

I’ve a little problem

If you press ENTER to submit form instead click on next button wizard always restart from the first step.

You can easily verify that by pressing ENTER on step2 in your user registration demo

Thanks in advance,

Marco


(Sb) #39

Sorry, but I don’t follow what you are saying here. Could you please give an example using registrationWizard on how to save each step to the database? Also, I want to have the user login to retrieve their profile rather than persist in the session. What do you recommend? Thanks!


(Sebastian Brams) #40

Hi,

this is a really nice extension.

Is there any solution for using this extension with active records? I have active records because of working with data from a database. Now I want to create new data by using such a wizard behavior. I want to combine a few forms and on submit the entries in the database will be created.

Problem is the "getForm()" function of the model, because my model is an active record.

Thx

Zebra