I am trying to use Wizard Behavior Extension. I wonder if such a code make sense (I am using CActiveRecord):
public function myWizardProcessStep($event) {
$data = array();
switch ($event->step) {
case "first" :
$d['form'] = "_contactform";
$d['model'] = new Contact();
$data[] = $d;
$d['form'] = "_addressform";
$d['model'] = new Address();
$data[] = $d;
//$model->attributes = $event->data; //<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />
break;
case "second":
...
}
if (isset($_POST['Address']) && isset($_POST['Contact'])) { //first step was posted
$model->attributes = $_POST['Address'];
//@todo: validation
$event->sender->save($model->attributes);
$event->handled = true;
}
else {...}
$this->render('wizard',
array( 'event'=>$event
, 'data'=>$data
));
And my wizard.php:
<?php $form = $this->beginWidget('GxActiveForm', array(
'id' => $event->step.'-form',
'enableAjaxValidation' => true,
));
?>
<?php
if (isset($data) && !empty($data))
{
foreach ($data as $key=>$d)
{
$this->renderPartial($d['form'], array(
'model' => $d['model']
,'form'=>$form
));
}
}
?>
<?php if ($event->$step != 'first') //@todo: stepNum != 1 <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />
{
echo CHtml::htmlButton(Yii::t('app', 'Previous'), array('class' => 'button', 'type' => 'submit', 'name'=>'previous'));
}
//@todo: last step->submit button
echo CHtml::htmlButton(Yii::t('app', 'Next'), array('class' => 'button', 'type' => 'submit', 'name'=>'next'));
$this->endWidget();
?>