Reputation: 1024
apologies if this is simple, I am trying to grab the selections from multiple checkboxes. I have created multiple checkboxes which look as follows:
<input type="checkbox" name="checkbox" value="a" id="selection">
<input type="checkbox" name="checkbox" value="b" id="selection">
<input type="checkbox" name="checkbox" value="c" id="selection">
I then can have a button and retrieve the form data using codeigniters built in form helper:
$temp = $this->input->post('checkbox');
if I select more than one checkbox however, and try to echo $temp, I only see one selection that a person has made. any ideas - ideally I don't want to use JS. Many thanks in advance
Upvotes: 1
Views: 699
Reputation: 66
You just need to add square brackets after checkbox name, like this:
<input type="checkbox" name="checkbox[]" value="a" class="selection">
<input type="checkbox" name="checkbox[]" value="b" class="selection">
<input type="checkbox" name="checkbox[]" value="c" class="selection">
This will pass checkboxes as array. Now you will get $this->input->post('checkbox') as something like this:
Array ( [0] => b [1] => c )
Upvotes: 2