Username availability checker

I’m sure this is easy but can’t find it. What class handles the in page username availability checker like the one the forum has. An example would be nice to.

You mean the unique validation rule?

http://www.yiiframework.com/doc/guide/form.model#declaring-validation-rules

http://www.yiiframework.com/doc/api/CUniqueValidator

I got that part. I want to do exactly like the forum does green box around it if it is good without having to submit.

Did you check CActiveForm? It can be configured to do what you want.

Trying to get it working now.

Got it working kinda. I understand how to send errors but how do I tell it good or set the border color on the field.

public function unique(){

	$username = $this->username;


	if ($this->username != ""){


		$user=User::model()->find('username=?',array($username));


		if($user===null){


		}


		else {


		$this->addError('username','Username already in use');		


		}


	}


}





protected function performAjaxValidation($model)


{


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


    {


		   echo CActiveForm::validate($model);


	        Yii::app()->end();


    }


}

<?php echo $form->labelEx($model,‘username’); ?>

<?php echo $form->textField($model,‘username’); ?>

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

Nevermind… Need to do this stuff while i’m not tired so I can read better sorry.

///////////Edit////////////

Related

Can you text the value of a input field using performAjaxValidation. Like if a enter last name Smith and it finds Bob for the first name it sets the input field firstname to Bob, or am i getting out side of built in functions now.

AFAIK not possible with ActiveForm.

Ok cool have the Java made for that already. Was just hoping yii had it by default.