Population of checkbox arrays in Validation library - 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: Population of checkbox arrays in Validation library (/showthread.php?tid=5564) |
Population of checkbox arrays in Validation library - El Forum - 01-26-2008 [eluser]marlar[/eluser] Hi, I think I have found a bug in the validation library. Checkboxes don't seem to get re-populated if they are part of a group, like: Code: echo form_checkbox('group[]','family', $this->validation->set_checkbox('group', 'family')); MODIFIED CODE; NOW IT ALSO WORKS FOR CHECKBOX GROUPS! Here is a modification of set_checkbox() in the validation libary so it works as expected: Code: function set_checkbox($field = '', $value = '') HOW TO USE IT: In the controller: Code: // for a single checkbox just use the checkbox' value: In the view: Code: <input type="CHECKBOX" name="mycheckbox" value="1" <?=$this->validation->set_checkbox('mycheckbox', '1')?>> Population of checkbox arrays in Validation library - El Forum - 02-07-2008 [eluser]Kinsbane[/eluser] Hi, question about this: If we have many checkboxes that store one or more values, and they share the name "mycolors[]", how would we go about setting that using $this->validation->set_fields() ? Would it be something like: $fields[mycolors[]] = mycolors[]; ? or just $fields[mycolors] = ''; Thanks for this! Population of checkbox arrays in Validation library - El Forum - 02-07-2008 [eluser]marlar[/eluser] I'm not sure I understand your question, but if you want to pre-fill the checkboxes, you do like this: $this->validation->mycolors = array("red","blue","yellow"); Where red, blue, yellow are the fields you want to have checked. Population of checkbox arrays in Validation library - El Forum - 04-16-2008 [eluser]Jeffrey04[/eluser] so will this fix be committed to the development repository soon? anyway, I just got this error after I replaced the code. The posting back of value seems to be correct though Quote:A PHP Error was encountered my view file looked like this Code: <li> and the controller Code: private function _get_meeting_validation_rules() { using codeigniter version 1.6.1 Population of checkbox arrays in Validation library - El Forum - 04-17-2008 [eluser]WeeJames[/eluser] Was getting the same as jeffery04. Fixed it by doing the following in Validation.php Code: function set_checkbox($field = '', $value = '') and Code: function prep_for_form($data = '') |