* beginWidget('CActiveForm', array( * 'id'=>'user-form', * 'enableAjaxValidation'=>true, * 'enableClientValidation'=>true, * 'focus'=>array($model,'firstName'), * )); ?> * * errorSummary($model); ?> * * * labelEx($model,'firstName'); ?> * textField($model,'firstName'); ?> * error($model,'firstName'); ?> * * * labelEx($model,'lastName'); ?> * textField($model,'lastName'); ?> * error($model,'lastName'); ?> * * * endWidget(); ?> *
* public function actionCreate() * { * $model=new User; * $this->performAjaxValidation($model); * if(isset($_POST['User'])) * { * $model->attributes=$_POST['User']; * if($model->save()) * $this->redirect('index'); * } * $this->render('create',array('model'=>$model)); * } * * protected function performAjaxValidation($model) * { * if(isset($_POST['ajax']) && $_POST['ajax']==='user-form') * { * echo CActiveForm::validate($model); * Yii::app()->end(); * } * } *
performAjaxValidation
beforeValidate(form) {...}
afterValidate(form, data, hasError) {...}
beforeValidateAttribute(form, attribute) {...}
afterValidateAttribute(form, attribute, data, hasError) {...}
* public function actionCreate() * { * $model=new User; * if(isset($_POST['ajax']) && $_POST['ajax']==='user-form') * { * echo CActiveForm::validate($model); * Yii::app()->end(); * } * ...... * } *
* * labelEx($model,'attribute'); ?> * textField($model,'attribute', array('id'=>'custom-id')); ?> * error($model,'attribute',array('inputID'=>'custom-id')); ?> * *
'.Yii::t('yii','Please fix the following input errors:').'
$_POST[ModelClass]
$_POST[ModelClass][$i]