Yii Framework Forum: Wizard Behavior - Yii Framework Forum

Jump to content

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • You cannot start a new topic
  • You cannot reply to this topic

Wizard Behavior Multi-step form handling Rate Topic: ***** 4 Votes

#21 User is offline   dave mc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 26-January 11

Posted 30 August 2011 - 09:33 AM

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?
0

#22 User is offline   Yeti 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 95
  • Joined: 30-May 09

Posted 11 September 2011 - 02:38 AM

View Postdave mc, on 30 August 2011 - 09:33 AM, said:

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?


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.
0

#23 User is offline   renathy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 82
  • Joined: 05-July 11

Posted 18 September 2011 - 03:31 AM

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.
0

#24 User is offline   russellfeeed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 01-September 11

Posted 19 September 2011 - 08:48 AM

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
0

#25 User is offline   russellfeeed 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 01-September 11

Posted 19 September 2011 - 12:45 PM

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
0

#26 User is offline   Saulo Vallory 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 16-September 11

Posted 25 September 2011 - 03:51 PM

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!
0

#27 User is offline   Yeti 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 95
  • Joined: 30-May 09

Posted 27 September 2011 - 06:37 AM

View Postrussellfeeed, on 19 September 2011 - 08:48 AM, said:

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


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.
0

#28 User is offline   Yeti 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 95
  • Joined: 30-May 09

Posted 27 September 2011 - 07:01 AM

View Postrenathy, on 18 September 2011 - 03:31 AM, said:

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').
...
Doesn't work. I guess that trying to check $_POST['step_name'] is not correct way. I am stuck.

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.
0

#29 User is offline   zanforlin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 06-September 11

Posted 30 September 2011 - 12:17 PM

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
0

#30 User is offline   renathy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 82
  • Joined: 05-July 11

Posted 03 October 2011 - 01:46 AM

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).
0

#31 User is offline   hany sarhan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 03-October 11

Posted 03 October 2011 - 09:42 AM

Looks nice, great work.
0

#32 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 603
  • Joined: 12-September 10
  • Location:Austria

Posted 14 November 2011 - 07:10 AM

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 :-(
should be OFF
0

#33 User is offline   szfjozsef 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 03-November 11
  • Location:Romania, Sfantu Gheorghe

Posted 12 December 2011 - 01:14 PM

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.
0

#34 User is offline   rmandovnz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 03-January 12
  • Location:Venezuela

Posted 03 January 2012 - 05:07 PM

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

#35 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 16 January 2012 - 02:42 PM

View PostPirificio, on 06 July 2011 - 02:20 PM, said:

HI there. I was wondering this myself for a long time. Here is what I did. Now assuming that I am only using the wizard for creating records, here is my controller:

/**
	* The wizard has finished; use $event->step to find out why.
	* Normally on successful completion ($event->step===true) data would be saved
	* to permanent storage; the demo just displays it
	* @param WizardEvent The event
	*/
	public function wizardFinished($event) {
		$command = Yii::app()->db->createCommand();
		if(isset($event->data['UserEmployeeProfile'])){
			$db_array = merge_array($event->data['User'],$event->data['ContactDetails'],$event->data['UserEmployeeProfile'],$event->data['UploadPhoto']);	
		}else{
			$db_array = array_merge($event->data['User'],$event->data['ContactDetails'],$event->data['UserEmployerProfile'],$event->data['UploadPhoto']);
		}

		if ($event->step===true){
				$command->insert('users',$db_array);
		
			
            // ...redirect to another page
			$this->render('completed', compact('event'));
		}else{
			$this->render('finished', compact('event'));
		}
		$event->sender->reset();
		Yii::app()->end();
	}


I had to test to see if UserEmployeeProfile or UserEmployerProfile was set because my wizard uses branching. Hope this helps!


Thank you so much for showing the array_merge line:)
-------------------------------------------------------

And what a killer extension. great job
0

#36 User is offline   Say_Ten 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 17-September 10

Posted 20 January 2012 - 05:30 AM

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:

  • staffForm
  • customerSearchForm
  • customerForm
  • documentationForm
  • confirmationForm


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?
0

#37 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 25 January 2012 - 07:51 AM

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.

3) 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 !!
CodeSutra
0

#38 User is offline   makro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 05-November 09
  • Location:Novara, IT

Posted 29 February 2012 - 01:18 PM

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
0

#39 User is offline   ivtdev 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 06-March 12

Posted 09 March 2012 - 06:51 PM

View PostYeti, on 23 August 2011 - 03:50 AM, said:

You simply read the data from the wizard with $wizard->read($step) - $step is optional and if empty returns all steps currently stored. Inside an event handler $wizard === $event->sender - so you would do $event->sender->read($step);


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!
0

#40 User is offline   zebra 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 04-March 12

Posted 06 April 2012 - 04:08 PM

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
0

Share this topic:


  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • You cannot start a new topic
  • You cannot reply to this topic

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