Welcome Guest, Not a member yet? Register   Sign In
Repopulating checkbox using CI syntax: confused.
#2

[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
$data = array(
    'name'        => 'bestemming[]',
    'id'          => 'industrie',
    'value'       => 'industrie',
    'checked'      => TRUE,
    'type'        => 'checkbox'
);
echo form_checkbox($data);
echo form_label('Industrie', 'industrie');



// CI generated checkbox, checked status determined by value
$checkval = "industrie2"; // quick test
// $checkval should be provided by the controller as part of data passed to the view

$data = array(
    'name'        => 'bestemming[]',
    'id'          => 'industrie2',
    'value'       => 'industrie2',
    'checked'      => (isset($checkval) && $checkval == "industrie2")?TRUE:FALSE,
    'type'        => 'checkbox'
);
echo form_checkbox($data);
echo form_label('Industrie 2', 'industrie2');

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.


Messages In This Thread
Repopulating checkbox using CI syntax: confused. - by El Forum - 08-23-2009, 10:59 AM
Repopulating checkbox using CI syntax: confused. - by El Forum - 08-24-2009, 12:41 AM
Repopulating checkbox using CI syntax: confused. - by El Forum - 08-24-2009, 05:12 AM
Repopulating checkbox using CI syntax: confused. - by El Forum - 12-26-2010, 03:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB