CodeIgniter Forums

Full Version: form_checkbox does not allow for multiple checkboxes (for an array value)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When using the code:
Code:
echo form_checkbox('newsletter', 'accept')

...the name assigned to the <input> element  will be:


Code:
<input type="checkbox" name="newsletter" value="accept" checked="checked" />

When using multiple checkboxes for similar items i.e. a To-Do list, the above causes the POST array to only contain the latest entry of the <input> element with the same name.

To get this to work, it needs to generate the following code (note the brackets):

Code:
<input type="checkbox" name="newsletter[]" value="accept" checked="checked" />

Is this currently possible in CodeIgniter?
Have you tried doing:


PHP Code:
echo form_checkbox('newsletter[]''accept'


If that doesn't work, you can pass a data array to the form_checkbox wherein you specify the attributes:


PHP Code:
$data = array(
    'name'        => 'newsletter[]',
    'value'       => 'accept
    );

echo form_checkbox($data); 


...which hopefully will work.