Welcome Guest, Not a member yet? Register   Sign In
Validating a group of fields...
#1

[eluser]mrtopher[/eluser]
I have a group of check boxes on a form that users need to fill out. When the form is submitted I need to make sure that they have checked at least one of these boxes. I'm having a problem wrapping my head around how I need to go about writing the custom validation for this.

I know you can create custom validation functions but in order for them to get called you need to associate them with a single field in the array you pass to set_rules(). I have tried a couple of different things and can't seem to get it working. Anyone know how I can accomplish this?
#2

[eluser]xwero[/eluser]
I presume you named your checkboxes like checkboxes[], in that case you can use the isset function to validate.
Code:
if(!isset($_POST['checkboxes']))
{
echo 'check at least one checkbox';
}
#3

[eluser]mrtopher[/eluser]
Thanks for the response.

I know how to validate the check boxes... what I'm having a problem with is getting the validation to run. When I enter:

Code:
$this->validation->set_rules(array('checkboxes'=>'required|callback_function'));

It doesn't always validate the checkboxes and I'm not sure why.
#4

[eluser]xwero[/eluser]
From what i have seen in the forum is that checkboxes are not supported well by the validation library therefore i think it's better to work out your own solution to make sure you get the right results.




Theme © iAndrew 2016 - Forum software by © MyBB