Just set the rules conditionally, since the rules change depending on the condition of another field.
Not sure I understand here. I need to check if a field is empty before checking the other field? or alternatively run a callback function on the first field, which says if the field is empty and field2 is empty then set a message and return false?
In either case, how do I get the value of a form field, using the form validation library? reading the documentation for the form validation library, I thought I might be able to get the values using set_value(‘email’); and set_value(‘phone’), but I don’t think this works. I’d have thought there is a “proper” way.
$this->form_validation->set_rules(‘email’, ‘Email’, ‘callback_emailphone_check’);
function emailphone_check($str)
{
if(empty($str) && empty(set_value('phone')))
{
$this->form_validation->set_message('emailphone_check', 'You must supply either a phone or an email address.');
return FALSE;
}
else
{
return TRUE;
}
}