1
votes

I have an array of two checkboxes in a form, setup the way this question suggests. Validation appears to fail, correctly, when no checkbox is selected but it looks like form_validation doesn't even run against empty checkboxes? Relevant code:

$this->form_validation->set_rules('groupcheck[]', 'groupcheck', 'required');

With no checkboxes selected this produces no errors when submitted (bad), and "validates" to false (good). When a checkbox is checked no errors are produced (good) and the form validates true (good).

Changing the validation to something which will always fail:

$this->form_validation->set_rules('groupcheck[]', 'groupcheck', 'valid_email');

With no checkboxes selected this produces no errors when submitted (bad), and "validates" to false (good). When a checkbox is checked a valid email error is produced (good) and the form validates false (good).

So is this an issue with the browser not returning any data to form_validation when no checkboxes are selected? How would you go about displaying errors when a checkbox isn't selected?

1
can you please post your controller + view code so we can check? - Laurence
posting some relevant code would help us know what is going on. but in the meantime, u might want to try showing individual errors - He Hui

1 Answers

0
votes

Ultimately I added a form_hidden() field to my view, then the form_validation will always run even with no checkboxes checked