Re-populating Array Check Boxes after Validation Failure |
[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.
[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/
[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/ |
Welcome Guest, Not a member yet? Register Sign In |