![]() |
Re-populating Array Check Boxes after Validation Failure - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Re-populating Array Check Boxes after Validation Failure (/showthread.php?tid=8437) |
Re-populating Array Check Boxes after Validation Failure - El Forum - 05-17-2008 [eluser]gkchicago[/eluser] I had trouble getting my array checkboxes to re-populate after a failed validation and have gotten it to work how I wanted without modifying the validation or input libraries so I thought I would share it here. I appreciate any input or opinions to help clean this up before I possibly make it a wiki entry. Important Note: I am not doing any validation on the checkbox itself, the checkboxes for my needs are considered optional in the context of the form. Methodology: A simple in_array check is used in the view to set the 'checked' (TRUE/FALSE) flag that is used by the form_checkbox function when outputting the checkboxes. Because my checkboxes have numeric ids a loop is used to keep the code relatively clean but is not required. The controller must pass the POST-ed array data back to the view on validation failure. View: Code: # Checkbox ids, probably loaded from a database active_checkboxes is set in the controller on validation failure. Controller: Code: function add() Because the checkboxes are outside the validation in the controller we need to check the post variables and set active_checkboxes for the reloaded view. Re-populating Array Check Boxes after Validation Failure - El Forum - 05-17-2008 [eluser]vadivelan[/eluser] Hi CI not dealing properly with user submitted array values through forms. To deal with that have a look at the below thread: http://ellislab.com/forums/viewthread/73012/ Re-populating Array Check Boxes after Validation Failure - El Forum - 05-18-2008 [eluser]gkchicago[/eluser] [quote author="vadivelan" date="1211106793"]Hi CI not dealing properly with user submitted array values through forms. To deal with that have a look at the below thread: http://ellislab.com/forums/viewthread/73012/[/quote] Hi vadivelan, I had run across your post while I was looking for the solution to this problem but I resisted using it because I didn't want to extend the code igniter validation library. But it looks like they are looking for something like your code for bug http://codeigniter.com/bug_tracker/bug/4530/ |