php - Yii Conditional Validation -
php - Yii Conditional Validation -
i have question yii validation. have dropdown options y , n. if user select y user must explain why chose y hence textarea box become required.
my code rule looks @ follows.
array('explain', 'check', 'trigger'=>'med_effects'),
check function used validation
public function check($attribute, $params) { if($this->$params['trigger'] == 0 && $this->$attribute == '') { $this->adderror($attribute, 'explain effects of medicine'); } } the value $this->$params['trigger'] not change. i'm assuming because saved value 0(y) , not alter if user take n. how supposed determine alternative user chose when sumbits form?
thanks.
create property within model:
public $isdropdownchecked; in view, create dropdown wired new property created.
and homecoming array of rules within method rules() this:
public function rules() { $rules[] = array(); if ($this->isdropdownchecked == 'y') $rules[] = array('explain', 'check', 'trigger'=>'med_effects'); homecoming $rules; } php forms validation yii
Comments
Post a Comment