Where do I customize form ajax validation error message

Where do I customize form ajax validation error message like ‘Username cannot be blank.’?


Are you using CActiveForm to render your form input elements?

If you just want to do localized error messages (ie: multilanguage) Yii should have most it’s default error messages already translated.

Otherwise You could use the rules function and declare the message property or create a custom validation function and just throw $this->adderror() on validation errors.

below you can see a custom validator @uniqueInGroup and the message property being used in numerical


	 * @return array validation rules for model attributes.


	public function rules()


		return array(

			array('group, title, value, order', 'required'),

			array('value, order', 'numerical', 'max'=>255, 'min'=>0, 'integerOnly'=>true, 'message'=>'Please choose a value with the slider'),

                        // unique group-title, group-value, group-order

                        array('title, value, order', 'uniqueInGroup'),

			// The following rule is used by search().

			array('group, title', 'safe', 'on'=>'search'),




         * Custom Validator checks if param+group hits on unique index


        public function uniqueInGroup($attribute,$params = null){

            // try to get an item with the $attribute in `group`:

            $item = Lookup::model()->find(array(

                    //'select'=>$attribute.', `group`',

                    'index'=> strtoupper('gand'.$attribute[0]),

                    'condition' => '`'.$attribute.'` = :'.$attribute.' AND `group` = :group',

                    'params' => array(


                            ':group'=>$this->group ,


            // if no item is returned new item will be unique

            if ($item != FALSE && $item->id != $this->id) // else throw error

                $this->addError($attribute, $this->getAttributeLabel($attribute).

                        ' '.$this->$attribute.' already exists in '.$this->group.

                        ' ('.$item->title.')'