Custom Validation

Hi All

I am trying to do custom validation but the error is not getting displayed.

steps i am following are

  1. defining rule in model array

  2. defining the function used in the model rule.

  3. displaying it in view form.


public function rules()



		return array(


array('idAgentApplication, PreviousExperienceCustomerService, WeekHoursContribution, LanguagesToSpeak, AboutYou, ResumeURL, ResumeFileName, FacebookLink, TwitterLink, Users_id, AccountProfile_Id, AgentApplicationStatus_Id, BluePass_id, LinkedIn', 'safe', 'on'=>'search'),




public function cust($attribute,$error)


       	 $this->addError('$attribute','my error');




public function actionConsultantApplication()





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


			//	'htmlOptions'=>array('class'=>'list_form'),




)); ?>

Thanks & Regards

this rule needs to be changed





Hi thanks for reply

but rule should contain the attribute name(WeekHourscontribution) and rule name(cust)

consultantApplication is view file name.

does the controller/action need some code?

but since buildin functions are working without any change in controller/action then why not custom functions?


please see this link

it may be helpful

Hi prats,

Is it exactly the controller code? I mean, does the method contain only one line?

If so, your custom validation method will never be called.

Note that not all validators support the client validation. Only some built-in validators that can produce a javascript for checking the value (without asking the server) are capable of the client validation.