Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii validation only if another field is present

Tags:

yii

I have two fields in my form named start date and end date. I want to validate end date only if start date is present.

In rails, we have :if. Do we have anything similar in yii?

like image 653
robert Avatar asked Mar 03 '12 04:03

robert


1 Answers

Define your custom function for validation .

define rule :

array('end_date','checkEndDate');

define custom function:

public function checkEndDate($attributes,$params)
{
  if($this->start_date){
     if(!$this->validate_end_date($this->end_date))
         $this->addError('end_date','Error Message');
  }  
}
like image 85
Onkar Janwa Avatar answered Nov 23 '22 21:11

Onkar Janwa