[eluser]Petsoukos[/eluser]
You will create your form the usual way. Create the checkboxes and setup their name attributes as array. e.g.
'name' => 'group1[ ]', See the example bellow.
Code:
echo form_open('the_link_to_your_controller');
// Group One
$data = array(
'name' => 'group1[]',
'value' => 'something',
'checked' => false
);
echo form_checkbox($data);
$data = array(
'name' => 'group1[]',
'value' => 'something_else',
'checked' => false
);
echo form_checkbox($data);
// Group Two
$data = array(
'name' => 'group2[]',
'value' => 'something',
'checked' => false
);
echo form_checkbox($data);
$data = array(
'name' => 'group2[]',
'value' => 'something_else',
'checked' => false
);
echo form_checkbox($data);
echo form_submit('submit', 'Submit');
echo form_close();
Ideally you should create a loop to construct those checkboxes dynamically.
Then in your controller grab those posted values and make a simple IF statement:
Code:
function process() {
$groupA = $this->input->post('group1');
$groupB = $this->input->post('group2');
if(!$groupA || !$groupB) {
echo 'Error!';
} else {
// your process goes here
}
}
Ideally the process should be made in the model.
This will guarantee that your user checked at least 1 checkbox on each group.
This is how I would do it and I've tested it and it works. I suggest you wait for other responses also. Maybe there is another more efficient way to do the same thing.