I've got a loop that generates checkboxes, I have it working within the view, but I would like to move it into the controller and then pass the resulting string to the view. The problem is set_checkbox() doesn't seem to remember the values when it's placed in a controller. It does however seem to set the default value.
Edit: This is only an issue when validation fails and I want checkboxes to retain the users selections. Otherwise code is working as expected. I also have a validation rule set.
$languages_by_name = $this->event_model->get_spoken_languages_by_name();
// Generate array from model data for form_dropdown()
$i = 1;
$list_languages = '';
foreach ($languages_by_name as $row) {
$i == 1 ? $first = TRUE : $first = FALSE; // Check if this is the first radio and precheck it.
$list_languages .= '<label>' . form_checkbox('spokenLanguages[]', $row->event_spoken_id, set_checkbox('spokenLanguages', $row->event_spoken_id, $first)) . ' ' . $row->name . '</label> ';
$i++;
}
// Pass $list_languages to view
$this->data['list_languages'] = $list_languages;
var_dump($list_languages)
might help a lot :) – Kyslik Jun 12 '13 at 22:37