Answer the question
In order to leave comments, you need to log in
How to solve the problem with the validation of the form connected via ajax?
I have a view:
<div class="row">
<div class="form-group">
<button class="btn btn-primary" id="add_form">Add form</button>
</div>
<div class="col-md-12" id="form">
</div>
</div>
public function actionAddForm()
{
$tourist = new Tourist();
return $this->renderAjax('add-form', [
'tourist' => $tourist
]);
}
<?php $form = ActiveForm::begin([
'action' => ['validate-form'],
'validationUrl' => ['validate-form'],
'enableAjaxValidation' => true,
'enableClientValidation' => true
]) ?>
<?= $form->field($tourist, 'name')->textInput() ?>
<?= $form->field($tourist, 'surname')->textInput() ?>
<?= Html::submitButton('sbmt', ['class' => 'btn btn-success']) ?>
<?php $form::end() ?>
public function actionValidateForm()
{
$tourist = new Tourist();
if(Yii::$app->request->isAjax && $tourist->load(Yii::$app->request->post()))
{
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($tourist);
}
}
Answer the question
In order to leave comments, you need to log in
that ajax requests are not sent at all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question