Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter form validation - at least one field is required

I have a submit form with 3 fields. At least one of the field should be filled in before submitting. Could you please help me to do it with codeigniter form validation.

controller

$this->form_validation->set_rules('country', 'Country','trim|strip_tags');
$this->form_validation->set_rules('state','State','trim|strip_tags');
$this->form_validation->set_rules('city','City','trimstrip_tags');
like image 765
EducateYourself Avatar asked Oct 22 '25 07:10

EducateYourself


1 Answers

Not a guru, but that will be my approach...

function do_add()
{
   if( (isset($_POST['country']) || (isset($_POST['state']) || (isset($_POST['city']) )
   {
      //Do stuff
   }
   else
   {
      //Redirect or whatever
   }
}
like image 65
tsompanis Avatar answered Oct 23 '25 19:10

tsompanis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!