【发布时间】:2015-05-31 14:17:42
【问题描述】:
我正在制作渐进式阶段注册表。
我将 $POST[''][''] 值存储在 Yii::app()->session['']
并在最后一步之后插入数据库。
现在我认为我需要为每个注册页面使用场景。
问题:
如何在不存储值的情况下验证每个注册页面
通过 $model->save() ?
我做了什么:
Controller.php
public actionCreate($id){
$model=new Admission;
if($id==0){
$model->setscenario('student');
Yii::app()->session['percent'] = 0;
if(isset($_POST['Admission']))
{
Yii::app()->session['admissionStudent'] = $_POST['Admission'];
if($model->validate('student')){
Yii::app()->session['percent'] = 25;
$this->redirect(array('create','id'=>$id+1));
}
else{
var_dump($model->getErrors());
}
}
}
}
Create_Form.php
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'admission-form',
//'enableAjaxValidation' => true,
//'htmlOptions' => array('enctype'=>'multipart/form-data'),
)); ?>
<?php echo $form->textFieldRow($model,'Name',array('class'=>'span4')); ?>
/* And other Fields */
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? 'Next' : 'Save & Proceed',
)); ?>
Model.php
public function rules()
{
return array(
array('Name,dob,SchoolLastAttended,
StandardLastStudied,QualifiedForPromotion,age,sex,medium',
'required','on'=>'student'),
}
错误
它显示每个字段都是空白并返回验证错误
var_dump
array(8) { ["Name"]=> array(1) { [0]=> string(41) "Name of the Pupil
cannot be blank." } ["dob"]=> array(1) { [0]=> string(37) "Date of
Birth cannot be blank." } ["SchoolLastAttended"]=> array(1) { [0]=>
string(71) "Name of the School last attended Primary/Middle cannot be
blank." } ["StandardLastStudied"]=> array(1) { [0]=> string(45)
"Standard Last Studied cannot be blank." } ["QualifiedForPromotion"]=>
array(1) { [0]=> string(70) "Whether qualified for promotion to
Standard VI cannot be blank." } ["age"]=> array(1) { [0]=> string(27)
"Age cannot be blank." } ["sex"]=> array(1) { [0]=> string(27) "Sex
cannot be blank." } ["medium"]=> array(1) { [0]=> string(30) "Medium
cannot be blank." } }
【问题讨论】:
标签: php validation yii