Repopulating checkbox using CI syntax: confused. |
[eluser]e-man[/eluser]
I'm working on a form built completely using the CI syntax and I'm looking for a way to repopulate a checkbox using that very syntax. This is the code for my checkbox: Code: echo form_label('Industrie', 'bestemming'); Now how do I combine this with the set_checkbox function?: Code: echo set_checkbox('bestemming', 'industrie');
[eluser]moonbeetle[/eluser]
Hi, from what I see in the user guide, set_checkbox() isn't meant to be used with the form_checkbox() method. Looks like set_checkbox() can only be used if you literally follow the example in the user guide, thus adding checkboxes in plain old HTML style, not CI generated style. Found a small error in your code, to output a checkbox CI style, use form_checkbox() instead of form_input. Also, for a checkbox, the data array can have a key called 'checked' which you set to have a value of TRUE/FALSE. This can be done hardcoded or dynamically (by matching the value of the checkbox). Code: // CI generated checkbox, checked='checked' by default About your question, "Repopulating", suggests you want to display the form again, after submit. Worth checking CI's validation class in combination with the form helper and validating arrays.
[eluser]e-man[/eluser]
Cheers mate! Although your second suggestion was even better: Set up a basic validation rule for the checkbox: Code: $this->form_validation->set_rules('bestemming[]', 'Bestemming', 'trim|required'); Code: $data = array(
[eluser]Medikal[/eluser]
I hate to dig up an old thread, but I have a ton of checkboxes such as this: Code: <? echo form_checkbox('category[]', 'apparel', ($this->form_validation->set_checkbox('category[]', 'apparel'))?TRUE:FALSE).'Apparel<br>'; ?> And it is failing to work, any suggestions? |
Welcome Guest, Not a member yet? Register Sign In |