Welcome Guest, Not a member yet? Register   Sign In
Conditioning the requirments validation on whether another condition was met
#1

[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?
#2

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

//...run validation




Theme © iAndrew 2016 - Forum software by © MyBB