V
V
Vmedmen2016-08-11 16:21:36
Yii
Vmedmen, 2016-08-11 16:21:36

Yii2. Data not parsed during ajax form validation?

Hi friends.

Faced an anomaly (for me). Before that, I worked a lot with Yii1, there were no such problems.

I work with the default registration form that is installed in yii2.

Additionally, I specified the settings:

$form = ActiveForm::begin(['id' => 'signupform',
                'enableAjaxValidation' => true,
                'enableClientValidation' => false]);


In the controller added:
if (\Yii::$app->request->isAjax && $model->load(\Yii::$app->request->isPost)) {
            \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
            return \yii\widgets\ActiveForm::validate($model);
        }


The bottom line is that the validation is in progress, the answer comes in the form of a page, but this page is not parsed to display errors on the current page.

Another interesting point. When I fill in all the fields correctly, automatic registration occurs, i.e. You don't even need to click the submit button.

And another moment. If I remove $model->load(...) in the controller, then the page with the response is parsed and errors are indicated everywhere Field can not be blank. It is right.

Maybe I missed something somewhere. I will be glad if you help.

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-08-11
@qualitat

$model->load(\Yii::$app->request->isPost)
replaced by
$model->load(\Yii::$app->request->post)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question