Controller action
Код: Выделить всё
public function actionForm()
{
if (isset($_POST['cancel']))
{
$this->redirect('/site/index');
} elseif (isset($_POST['step2']))
{
$this->setPageState('step1',$_POST['Test']); // save step1 into form state
$model=new Test('step1');
$model->attributes = $_POST['Test'];
if($model->validate())
$this->renderPartial('form2',array('model'=>$model));
else
$this->renderPartial('form1',array('model'=>$model)); echo "<pre>";print_r($this->getPageState('step1',array()));
} elseif (isset($_POST['finish']))
{
echo "<pre>";print_r($this->getPageState('step1',array())); die;
$model=new Test('finish');
$model->attributes = $this->getPageState('step1',array()); //get the info from step 1
$model->attributes = $_POST['Test'];
if($model->validate()) {echo ok; die;}
echo"no"; die;
if ($model->signup())
$this->redirect('/site/index');
else
$this->renderPartial('form2',array('model'=>$model));
} else
{ // this is the default, first time (step1)
$model=new Test('new');
$this->renderPartial('form1',array('model'=>$model));
}
//return $this->render('form', array('model'=>$model));
}
Код: Выделить всё
<?php $form=$this->beginWidget('CActiveForm', array(
'enableAjaxValidation'=>false,
'id'=>'model-form',
'stateful'=>true,
));?>
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username', array('class'=>'span5')); ?>
<?php echo $form->error($model,'username'); ?>
<?php
echo CHtml::submitButton("Cancel",array('name'=>'cancel'));
echo CHtml::submitButton("On to Step 2 >",array('name'=>'step2'));
$this->endWidget(); ?>
Код: Выделить всё
<?php $form=$this->beginWidget('CActiveForm', array(
'enableAjaxValidation'=>false,
'id'=>'model-form',
'stateful'=>true,
));?>
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email', array('class'=>'span5')); ?>
<?php echo $form->error($model,'email'); ?>
<?php
echo CHtml::submitButton("Back to Step 1",array('name'=>'step1'));
echo CHtml::submitButton("Finish",array('name'=>'finish'));
$this->endWidget(); ?>
Код: Выделить всё
<?php
class Test extends CFormModel {
public $username;
// public $password;
public $email;
// public $verifyCode;
//private $_identity;
public function rules() {
return array(
array('username, email', 'required', 'on'=>'new'),
//array('username', 'required'),
//array(' username','safe'),
array('username','required', 'on'=>'step1'),
array('username','safe', 'on'=>'step1'),
array('email', 'required', 'on'=>'finish'),
//array('email', 'safe'),
array('email', 'safe', 'on'=>'finish'),
//array('password', 'authenticate'),
);
}
public function attributeLabels() {
return array(
'username' => 'Логин',
'password' => 'Пароль',
'email' => 'Email',
'verifyCode' => 'Код проверки',
);
}
// public function step1() {
// $criteria=new CDbCriteria;
// $criteria->compare('username',$this->username,true);
// return new CActiveDataProvider($this, array(
// 'criteria'=>$criteria,
// ));
// }
// public function step2() {
// $criteria=new CDbCriteria;
// $criteria->boolean('email');
// return
// $criteria;
// }
public function signup()
{
$user = new User;
$user->username = $this->username;
$user->password = $user->hashPassword($this->password);
$user->email = $this->email;
$user->create_user_id = 1;
//$user->create_date = date('Y-m-d');
$user->update_user_id = 1;
//$user->update_date = date('Y-m-d');
$user->group_id = 1;
$user->is_deleted = 0;
if($user->save())
{
$user->create_user_id = $user->id;
$user->update_user_id = $user->id;
return $user->save();
}
}
}
?>