If set_checkbox() or set_radio() with arrays doesn't work... - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: If set_checkbox() or set_radio() with arrays doesn't work... (/showthread.php?tid=13043) |
If set_checkbox() or set_radio() with arrays doesn't work... - El Forum - 11-08-2008 [eluser]simshaun[/eluser] Once again, I spent literally hours racking my brain over this and trying different combinations between the view and controller... If you have checkboxes or radios who's name is an array (ex: name="privelages[]"), and you try to use set_checkbox('privelages[]', 'expected-value') on them, it won't work! I was doing this because in the documentation, it says to. (But wait! It only shows using the brackets in the set_value() function.) The solution, I'm glad to say, is to take the [] part off of the name in set_checkbox(). Code: set_checkbox('privelages[]', 'expected-value') This is because the set_checkbox function was checking for a key called "privelages[]" in its version of the post array. It won't find it because PHP has converted privelages to an array already, so the post array looks something like this: Code: 'privelages' => NOT... Code: 'privelages[]' => Hope this helps someone. If set_checkbox() or set_radio() with arrays doesn't work... - El Forum - 12-27-2008 [eluser]no_Ob[/eluser] Thank you simshaun It helped me lot. I was wondering why I can't see the posted variables in my controller |