I have a contact form that has both an email address and a telephone number. Is there a way to set a model rules() rule that validates for one OR the other OR both, but NOT neither. Meaning:
public function rules()
{
return array(
array('email', 'email'), // this rule allows email to be empty.
array('phone', 'someValidator...'),
array('email', 'filledContacts'),
);
}
public function filledContacts($attribute, $params)
{
if (!$this->hasErrors('email') && !$this->hasErrors('phone')) // If any contact field has validation errors, then don't show a message.
{
if (empty($this->email) && empty($this->phone))
$this->addError('email', 'Fill at least a email!');
}
}