Yii Ajax Validation in widget not working

I’m using Ajax validation in my widget. Tried this for hours but it’s not working still. Please help!!

Widget function

public function run(){




$model= new LoginForm;

// if it is ajax validation request

if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')


    echo CActiveForm::validate($model);






        // validate user input and redirect to the previous page if valid

        // blah blah.......

Widget View:

<?php $form=$this->beginWidget('CActiveForm', array(


    'enableAjaxValidation'=> true,





)); ?>

    <div class="row">

        <?php echo $form->textField($model,'username',array('placeholder'=>'email','class'=>'form-control')); ?>

        <?php echo $form->error($model,'username'); ?>


    <div class="row">

        <?php echo $form->passwordField($model,'password',array('placeholder'=>'password','class'=>'form-control')); ?>

        <?php echo $form->error($model,'password'); ?>


    <div class="row buttons">

        <?php echo CHtml::submitButton('Login', array('class'=>'btn btn-primary btn-block')); ?>



Right now the form is not submitting. After I click login nothing happens.

If I make enableAjaxValidation fale, form works but not AJAX.

If I make enableClientValidation false, form works but still no AJAX.

Any ideas? Thanks.

You have to use ‘afterValidate’ inside ‘clientOptions’. Use $.ajax() function to submit the data.





                                        "url":"your url",



                                        "error":function(xhr, status, error){alert(xhr.responseText);},




Sorry but that does not work :(

Whether ajax validation is working? Did you check in the browser’s network console?

Yes. nothing happens there. form doesn’t get submitted.

Whether the form is available online? Can you post the link?