I have a form validation rule in place for a form that has a number of checkboxes:
$this->form_validation->set_rules('groupcheck[]', 'groupcheck', 'required');
If none of my checkboxes are checked upon submission, my code never gets past the validation->run as the variable does not exist:
if ($this->form_validation->run()):
If i surround my validation rule with a check for the var, the validation never passes as there are no other form validation rules:
if(isset($_POST['groupcheck'])):
$this->form_validation->set_rules('groupcheck[]', 'groupcheck', 'required');
endif;
How can I manage a checkbox validation rule where the var may not exist, and it will be the only form variable?
Regards, Ben.
requiredfor ? If you need at least one checkbox checked then your first code is ok. If it is not required, just remove it...code$this->form_validation->set_rules('groupcheck[]', 'groupcheck', ''); if ($this->form_validation->run()): echo "test";