CodeIgniter Forums

Full Version: {SOLVED]Conditional Validation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]eric cumbee[/eluser]
i have a form that is broken up into several sections. some sections only need to be filled out in certain circumstances, mainly if the user checked a check box. im using jquery to hide and show those sections based on the user input. that is working fine.

the question i have now, is how do i setup form validation (using the CI form validation) so that if a certain check box is not checked, it will not worry about validating the fields in that form section.

El Forum

[eluser]Krzemo[/eluser]
What about checking states of checkboxes first and then building validation rules for desired fields based on that?

El Forum

[eluser]adamp1[/eluser]
I think you will have to do something like:
Code:
if($this->input->post('checkbox'))
{
    $this->form_validation->set_rules('field','Field','your rules');
}

Currently there is no Conditional form validation in CI. That or write a new custom rule to handle the case and possibly patch the Form_validation class.

El Forum

[eluser]eric cumbee[/eluser]
that worked i did not think it would be that simple