Validation of Yii- client side does not work on CActiveForm

I have an active form in my application. But client side validation does not work. The form code looks like this:

<?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'application-data-student-form', 'enableAjaxValidation'=>false, 'enableClientValidation'=>true, 'clientOptions'=>array('onSubmit'=>true), 'htmlOptions'=>array( 'enctype'=>'multipart/form-data', 'role'=>'form', 'class'=>'form-horizontal' ), )); ?> 

I used bootstrap 3 in my project. Any idea or solution would be highly appreciated by anyone.,.

+6
source share
2 answers

I finally solved the problem. I am posting this so that it helps someone with the same problem.

The problem arose due to incorrect loading of jquery.js into the application. The map file was missing, which is required by jquery.js. So I downloaded the latest jquery 2.1.1.min.js and the corresponding map file from [ http://jquery.com/download/] and loaded them into the main layout. Now validation is finally working.

We hope this workaround helps someone with the same problem.

+3
source

Try adding something like this to the model action:

 if (Yii::app()->request->isAjaxRequest){ echo CActiveForm::validate($model); Yii::app()->end(); } 

or does not match this line

 // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); 
+1
source

Source: https://habr.com/ru/post/970234/


All Articles