Yii2 ajax验证表单输入

MemberController.php
public function actionEditInfo()
{
    $model = EditInfoForm::findOne(Yii::$app->user->id);

    //ajax验证
    if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
        Yii::$app->response->format = Response::FORMAT_JSON;
        return ActiveForm::validate($model);
    }


    if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post()) && $model->validate()) {
        $model->save();
    }

    return $this->render('setting-info', ['model' => $model]);
}

view.php
[
        'template'=> "{input}{error}"//重要
    ]
]); ?>
生日
'grse-listr-qrtj']) ?>

你可能感兴趣的:(yii2)