When client validation is enabled, everything works fine, but as soon as I turn it off and turn on Ajax validation, everything stops working and an error constantly appears that the field is not filled. Although it is, of course, filled.
View
<?php $form = ActiveForm::begin([ 'enableClientValidation' => false, 'enableAjaxValidation' => true, ]);?> <?=$form->field($model, 'name')->label('Full Name')?> <?=$form->field($model, 'email')->label('Email Address')?> <?=$form->field($model, 'subject')->label('Subject')?> <?=$form->field($model, 'body')->label('Message')->textarea(['rows' => 6])?> <?=$form->field($model, 'verifyCode')->widget(Captcha::className(),[ 'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>', ]);?> <?=Html::submitButton('Send Message', ['class' => 'btn btn-success'])?> <?php ActiveForm::end() ?>
Controller
public function actionContact(){ $model = new ContactForm(); if(Yii::$app->request->isAjax && Yii::$app->request->isPost){ Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if($model->load(Yii::$app->request->post()) && $model->validate()){ Common::sendMail($model->email, $model->subject, $model->body, 'Name'); } return $this->render('contact',[ 'model' => $model, ]); }
Model (rules)
public function rules() { return [ [['name', 'email', 'subject', 'body'], 'required'], ['email', 'email'], ['verifyCode', 'captcha'], ]; }