Welcome Guest, Not a member yet? Register   Sign In
{SOLVED]Conditional Validation
#1

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

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

[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.
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB