[eluser]vertmonkee[/eluser]
In my form I have some checkboxes that are created based on a database table.
The table contains organisations the user can agree to share data with.
The organisations are put into an array with their id as the key and name as the value
Code:
$organisations = array();
$organisations[21] = 'First organisation';
$organisations[57] = 'Second organisation';
$organisations[98] = 'Third organisation';
I need to create the checkboxes from this which I am happy with. The problem I am having is when the user submits the form with incorrect information. They are then shown the form again but I can't figure out how to 'check' the checkboxes again.
I came up with this which creates the checkboxes but does not recheck them
Code:
<?php
foreach($organisations as $key => $value) {
?>
<li>
<label for="organisation"><?php echo $value; ?></label>
<?php echo form_checkbox("organisation[]", array(
'name' => 'organisation[]',
'value' => $key,
'checked' => set_checkbox('organisation[]', $key)
)); ?>
</li>
<?php
}
?>
Any help would be greatly appreciated.
Thanks