• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation, either or

#1
[eluser]Hamilogre[/eluser]
Hi, I'm looking for a way to force validation on one field, OR another field.

I have a primary phone number field, and a secondary phone number field. I want one of them to be required. How can I accomplish this?

#2
[eluser]Colin Williams[/eluser]
You just need a humble little IF control statement:

Code:
$rules['phone1'] = 'required';
if ( ! $this->input->post('phone1'))
{
   unset($rules['phone1']
   $rules['phone2'] = 'required';
}

Note that the condition to match might be more complex than that. You could otherwise have a check_phone_no() callback that essentially does the same thing... might be a little cleaner that way.

#3
[eluser]Hamilogre[/eluser]
Aaaahhh, makes total sense! Thanks, I'll try it out.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.