CodeIgniter Forums
Conditioning the requirments validation on whether another condition was met - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Conditioning the requirments validation on whether another condition was met (/showthread.php?tid=59342)



Conditioning the requirments validation on whether another condition was met - El Forum - 09-23-2013

[eluser]Unknown[/eluser]
I inherited my first CI project from another developer. I need to modify the validation of 2 different forms based on if another field was selected (checkboxes, in one case) and if a form field has information in it (another case).

For the first case, if a check box is selected (from the group funding_programs[]), then a group of validation rules must be set, if not, then they are not required.

Here is my code snippet in the __validation_rules():

Code:
//If 'precollege' is selected
array('field' => 'pre_college_support[]', 'rules' => 'required'),
array('field' => 'pre_college_support_other', 'rules' => ''),
array('field' => 'pre_college_assoc', 'rules' => 'required'),
array('field' => 'pre_college_occur[]', 'rules' => 'required'),

//If 'public outreach' is selected
array('field' => 'public_outreach_support[]', 'rules' => 'required'),
array('field' => 'public_outreach_support_other', 'rules' => ''),

//If 'teacher' is selected
array('field' => 'teacher_support[]', 'rules' => 'required'),
array('field' => 'teacher_support_other', 'rules' => ''),

Doe the validation load on submit and has access to the $_POST or $_GET?


Conditioning the requirments validation on whether another condition was met - El Forum - 09-23-2013

[eluser]CroNiX[/eluser]
Code:
if ($this->input->post('some_field') == 'some_val')
{
  $this->form_validation('different_field', 'different field', set another rule);
}

//...run validation