Yii AJAX form validation on submit

From: YII ยป How to use AJAX form validation

One potentially confusing thing about Yii’s AJAX form validation is that it works when you tab out of a field, but the default code doesn’t do the AJAX validation when you hit the submit button.

While you are going to be validating on the server anyway, but if it’s a particularly large page, you might want to avoid the page reload.

To enable AJAX validation in Yii:

In your view (_form.php):

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

And in your controller, in actionCreate and actionUpdate, uncomment these lines:


3 Responses to “ “Yii AJAX form validation on submit”

  1. Nilakshi says:

    I want to validate a form using yii ajax validation. but yet don’t get a good example.

  2. Novazembla says:


    thanks for you post. It helped me a bit further. Found somewher the CActiveForm ‘clientOption’. With it you can enable ajaxValidation on submit!

    beginWidget(‘CActiveForm’, array(

    )); ?>

    More info: http://stackoverflow.com/questions/6348581/yii-ajaxsubmitbutton-with-fields-validation

Leave a Reply