Ajax Validation For Chtml::textfield On Onchange Event

i have a functionality in my website where when user enters email address … i validate email address that it did not exist in database if it exist i want to set errors by addErrors() method described in yii/framework/base/cmodel.php … in controller action … i know it will not work until page loads again … so i want to addError or do something similiar to that …which returns false and prevent from to get submitted untill they do not solve the error(write a unique email address)…

check this artical

otherwise you can add a flash message on view file…

 if ($_POST['Users']['email'] != '') {

                $Obj = $model->findByAttributes(array('email' => $_POST['Users']['email']));

                if (isset($Obj->attributes)) {

                    $model->attributes = $_POST['Users'];

                    Yii::app()->user->setFlash('error', Yii::t("messages", "There is already an account with this email address, please try again.!"));

                    $this->render('create', array('model' => $model,));




simply write in your model rules like this

array('email', 'unique', 'message' => Yii::t("validation","This email already exists."))