Create Rule In Form Model




class RegisterForm extends CFormModel

{

	public $firstName;

	public $lastName;

	public $email;


	public function rules()

	{

		return array(

			array('firstName, lastName, email', 'required'),

			array('email', 'email'),

			array('email', 'checkEmail'),

		);

	}

	

	public function attributeLabels()

	{

		return array();

	}


	public function checkEmail()

	{

		$record = Account::model()->findByAttributes(array('username'=>$this->email));

		if ($record==null) {

			return true;

		}

		return false;

	}

}



but not working. Somebody can help me?




public function checkEmail($attribute, $options)

{

  $record = Account::model()->findByAttributes(array('username'=>$this->email));

  if ($record !== null) {

    $this->addError('email', 'Your error message');

  }

}



Guide.

I did like that, when checked, I had the error, but not ajax announcement? why is that?