Answer the question
In order to leave comments, you need to log in
How to make require validation with OR in yii?
How to use require validator with OR in Yii model.
For example, it requires a person to enter a phone number or email address, but one or both is required.
Answer the question
In order to leave comments, you need to log in
public function rules() {
return array(
array('username','either','other'=>'email'),
);
}
public function either($attribute_name, $params)
{
$field1 = $this->getAttributeLabel($attribute_name);
$field2 = $this->getAttributeLabel($params['other']);
if (empty($this->$attribute_name) && empty($this->$params['other'])) {
$this->addError($attribute_name, Yii::t('user', "either {$field1} or {$field2} is required."));
return false;
}
return true;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question