Answer the question
In order to leave comments, you need to log in
How does native Ajax validation work in Yii2?
Let's say I want to check if a field is unique.
In the view I enable enableAjaxValidation:
$form = ActiveForm::begin([
'id' => 'signup-form',
'enableAjaxValidation' => true,
]);
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
Answer the question
In order to leave comments, you need to log in
To submit form data without reloading the page, hook the event:
$('#signup-form').on('beforeSubmit', function(e){
console.log('beforeSubmit');
return false;
});
The request will be processed without your participation, if you have done everything correctly.
Look at the lesson, everything will be clear here https://www.youtube.com/watch?v=URhvUwebSvc
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question