1

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

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
TotalNewbie
  • 1,004
  • 5
  • 13
  • 25
  • Firstly, don't use the same ID for multiple elements, the ID should always be unique. – DBS Jan 15 '14 at 17:57
  • As for your question, I believe [this](http://stackoverflow.com/questions/4997252/get-post-from-multiple-checkboxes) might help. – DBS Jan 15 '14 at 18:00

1 Answers1

1

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 )
Zulu
  • 56
  • 5