04-12-2011, 10:02 AM
[eluser]Brad K Morse[/eluser]
Using version 2
Unable to retain the items selected by the user within a form_multiselect when the form is redisplayed after the user did not complete the entire form
It does not retain any items selected by the user when using set_select, but it retains one item if you use set_value
Using version 2
Unable to retain the items selected by the user within a form_multiselect when the form is redisplayed after the user did not complete the entire form
Code:
// controller
$this->form_validation->set_rules('goal_id[]', 'Goal', 'required'); // rule
$form_view['goals'] = $this->add_model->getGoals(); // getting goals
$this->load->view('add-assessment/form-view', $form_view);
// model
function getGoals() {
$this->db->cache_on();
$q = $this->db->order_by('id', 'asc')->get('goal');
if($q->num_rows() > 0) {
foreach($q->result() as $row) {
$data[$row->id] = $row->title;
}
return $data;
}
}
// view
<?=form_label('Goals')?>
<?=form_error('goal_id[]')?>
<?=form_multiselect('goal_id[]', $goals, set_select('goal_id[]'))?>
It does not retain any items selected by the user when using set_select, but it retains one item if you use set_value