$form->field($model, 'email', ['enableClientValidation' => false, 'enableAjaxValidation' => true])
public function rules()
{
return [
// name, email, subject and body are required
[['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address
['email', 'checkDate'],
// verifyCode needs to be entered correctly
['verifyCode', 'captcha'],
];
}
public function checkDate($attribute, $param) {
$this->addError('email', 'Значение: Проверка работы кода для вопроса от @Aricus '.$this->$attribute);
}
public function actionContact()
{
$model = new ContactForm();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
]);
}
if(\Yii::$app->request->isAjax){ // ajax-валидация
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {