Welcome Guest, Not a member yet? Register   Sign In
form_checkbox does not allow for multiple checkboxes (for an array value)
#1

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?
Reply
#2

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB