CodeIgniter Forums
Question regarding $this->input->post() and checkboxes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Question regarding $this->input->post() and checkboxes (/showthread.php?tid=14901)



Question regarding $this->input->post() and checkboxes - El Forum - 01-19-2009

[eluser]RS71[/eluser]
I'm currently making a form but I'm having some trouble adding a check box.

The check box doesn't return a value unless it is checked, right?

If I use $this->input->post(), will it give me an error if there is no check in the box (no check box value present in POST) or will it return false or something?


Question regarding $this->input->post() and checkboxes - El Forum - 01-19-2009

[eluser]Ivan A. Zenteno[/eluser]
Are you sure using this syntax $this->input->post("check_box_name") ?

The user guide http://ellislab.com/codeigniter/user-guide/libraries/input.html


Question regarding $this->input->post() and checkboxes - El Forum - 01-20-2009

[eluser]darkhouse[/eluser]
it would/should return false.


Question regarding $this->input->post() and checkboxes - El Forum - 01-20-2009

[eluser]Ivan A. Zenteno[/eluser]
Are you sure the name input tag is the same?


if you print_r($_POST) what is the output?


Question regarding $this->input->post() and checkboxes - El Forum - 01-20-2009

[eluser]nikefido[/eluser]
How are you naming your checkboxes? If you have multiple checkboxes with the same name, you typically name them something like name="myCheckBox[]"

This then returns an array which you can use to gather all the values of that set of checkboxes. Perhaps you're getting an empty array back?


Question regarding $this->input->post() and checkboxes - El Forum - 06-12-2011

[eluser]Unknown[/eluser]
Thanks nikefido - I was having the same problem, but adding the [] to the checkbox names fixed it for me.