Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii - Using Ajax Validation

Tags:

ajax

yii

I'm trying to enable ajax validation in a form, I've added the right parameters to the form, but it's not working, here's my code:

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'user-form',
    'enableAjaxValidation'=>true,
    'htmlOptions' => array(
            'enctype' => 'multipart/form-data',
            'enableClientValidation'=>true
    ),
)); ?>

Please advice.

like image 867
Jason Statham Avatar asked Apr 18 '13 17:04

Jason Statham


1 Answers

In the top of your action, add the following lines:

if(isset($_POST['ajax']) && $_POST['ajax']==='user-form'){
    echo CActiveForm::validate($model);
    Yii::app()->end();
}
like image 69
Mohammad Anini Avatar answered Oct 27 '22 01:10

Mohammad Anini