Validating That At Least One Checkbox Is Selected Using Codeigniter Validation Class?May 3, 2011
I have a codeigniter form that contains two checkboxes:
<input type="checkbox" checked="checked" id="box1" name="box1" /> <label for="box1">Box One</label>
<input type="checkbox" checked="checked" id="box2" name="box2" /> <label for="box2">Box Two</label>
I want to use CI form validation to check that at least one checkbox is select (more than one can be selected). I'm having problems working out how to do it with the form validation libaray. I tried a callback but this only passes the value of one checkbox. Whats the best way to validate?
There are also other fields on the form, so I need to maintain the state of the checkboxes on validation.