set_value, set_select for form_multiselect in v2 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: set_value, set_select for form_multiselect in v2 (/showthread.php?tid=40555) |
set_value, set_select for form_multiselect in v2 - El Forum - 04-12-2011 [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 Code: // controller It does not retain any items selected by the user when using set_select, but it retains one item if you use set_value set_value, set_select for form_multiselect in v2 - El Forum - 04-12-2011 [eluser]zac[/eluser] According to the user guide, set_select() is intended to be used when you're generating the select HTML by hand, like this: Code: <select name="myselect"> Instead, form_multiselect() wants an array of values as its third parameter. The $_POST array will contain whatever values the user selected: Code: <?=form_multiselect('goal_id[]', $goals, $_POST['goal_id[]'])?> Or if you're using CI's Input class, then something like this: Code: <?=form_multiselect('goal_id[]', $goals, $this->input->post('goal_id[]'))?> |