CActiveForm, ajax & validation

Hi All

I was try to use documentation and create model, form & controller for submitting form by ajax.

But validation do not work.

Please, help to fix this problem


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







                )); ?>



                        echo CHtml::ajaxSubmitButton('Отправить сообщение', '', array(

                            'type' => 'POST',

                            'update' => '#contact-form-div',


                        array('type' => 'submit'));



<?php $this->endWidget();?>


 public function actionIndex(){

                 $model=new ContactForm; 



                $flashMessage = 'Наш консультант свяжется с вами...';






                                echo CHtml::encode($onlineform);








       protected function performAjaxValidation($form,$model){

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


                echo CActiveForm::validate($model);




moidel ContactForm:



 * ContactForm class.

 * ContactForm is the data structure for keeping

 * contact form data. It is used by the 'contact' action of 'SiteController'.


class ContactForm extends CFormModel


	public $name;

	public $email;

	public $phoneNumber;

	public $subject;

	public $body;

	public $verifyCode;

        public $readOnly = false;


	 * Declares the validation rules.


	public function rules()


		return array(

			// name, email, subject and body are required

			array('name, email, phoneNumber, body, verifyCode', 'required'),

			// email has to be a valid email address

			array('email', 'email'),

                        array('subject, phoneNumber','safe'),

			array('phoneNumber', 'length', 'max'=>16),

			array('phoneNumber', 'length', 'min'=>16),

			array('phoneNumber', 'match','pattern' =>'/^((\+?7)\(*(\d{3})\)*)(\d{3})(-?\d{2})(-?\d{2})$/',

                                'message' => 'Некорректный формат поля "{attribute}"'),

			// verifyCode needs to be entered correctly

			array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),




	 * Declares customized attribute labels.

	 * If not declared here, an attribute would have a label that is

	 * the same as its name with the first letter in upper case.


	public function attributeLabels()


		return array(	

                        'name' => 'Ваше имя',

                        'email' => 'Ваш email',

                        'subject' => 'Тема сообщения',

			'phoneNumber' => 'Телефон для связи',

                        'body' => 'Опишите кратко свою проблему', 

			'verifyCode'=>'Код верификации',