我讀過類似的這個問題的主題,但我沒有找到解決方案。我有一個通過ajax加載的表單。當所有的數據是有效的,他們沒有在數據庫保存,並告訴我驗證錯誤console.in我的用戶模型我** ** set return parent::beforeSave(); in beforeSave method
這是我的行動:
public function actionRegister()
{
$model = new RegistrationForm;
if(isset($_POST['ajax']) && $_POST['ajax']==='register-form')
{
$this->ajaxValidate($model);
}
if(isset($_POST['RegistrationForm']))
{
if($model->validate())
{
$model->attributes = $_POST['RegistrationForm'];
$user = new User;
$user->attributes = $model->attributes;
if($user->save())
echo 1;
}else{
$errors = $model->getErrors();
var_dump($errors);
exit;
}
}
$this->renderPartial('register', array('model' => $model),false,true);
public function ajaxValidate($model)
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
請出示'var_dump'。 – Mave