Custom Validation Not Working- Yii2-app-basic-Yii2

前端 未结 5 2313
借酒劲吻你
借酒劲吻你 2021-01-20 09:48

I Posted one question yesterday regarding custom validation for radio button Textfield Mandatory On Radio Button. I got answer. But, that was not exact answer. But, it solve

5条回答
  •  花落未央
    2021-01-20 10:05

    @Nana Partykar

    As you asked how the ajax validation can be disabled for the captcha i tried this way. But i am not sure if this is the correct way.

    I have set to the the form with this settings

    'enableAjaxValidation' => true,
    'enableClientValidation' => false,
    'validateOnSubmit' => false,
    

    and changed the validation on the action to this (i removed my captcha in my case 'verifyCode' from the attributes which should be validated.

    if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
            Yii::$app->response->format = 'json';
            $validateAttributes = $model->activeAttributes();
            $key = array_search('verifyCode', $validateAttributes);
            if ($key!==false) {
                array_splice($validateAttributes, $key, 1);
            }
            return \yii\widgets\ActiveForm::validate($model, $validateAttributes);
    }
    

提交回复
热议问题