![]() |
Checkboxes - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Checkboxes (/showthread.php?tid=9724) |
Checkboxes - El Forum - 07-06-2008 [eluser]stuffradio[/eluser] What method do you use for check boxes? I just want them to have a value of true and false. If it's checked when the form is submitted, it'll say true in the database, if not it will be false. Checkboxes - El Forum - 07-06-2008 [eluser]marcoss[/eluser] 1 and 0. Checkboxes - El Forum - 07-06-2008 [eluser]stuffradio[/eluser] That doesn't answer anything... Checkboxes - El Forum - 07-06-2008 [eluser]Colin Williams[/eluser] Use 1 for the true value, and 0 for the false value. You can do a set(0,1) or enum(0,1) field in your DB if you'd like Checkboxes - El Forum - 07-06-2008 [eluser]Michael Wales[/eluser] Code: $input['my_checkbox'] = FALSE; Checkboxes have a value of 'on' if they are checked and they are not passed through at all if unchecked. Checkboxes - El Forum - 07-07-2008 [eluser]flojon[/eluser] [quote author="Michael Wales" date="1215423869"] Code: $input['my_checkbox'] = FALSE; Or in one line (since $this->input->post will return false if the item is not set) Code: $input['my_checkbox'] = $this->input->post('my_checkbox') !== FALSE; (I'm not sure isset will work.. Will it?) Checkboxes - El Forum - 07-07-2008 [eluser]Seppo[/eluser] isset won't work on expressions, only does with variables Code: // you can't Checkboxes - El Forum - 07-08-2008 [eluser]Noinx[/eluser] You can use this code in your view when adding checkboxes: Code: <input type="hidden" name="myCheckbox" value="0" /> By using the hidden field, the value will be 'zero' if the box is not checked. For me this is preferred over not getting anything back about the field. Checkboxes - El Forum - 07-22-2008 [eluser]Yash[/eluser] [quote author="Michael Wales" date="1215423869"] Code: $input['my_checkbox'] = FALSE; Checkboxes have a value of 'on' if they are checked and they are not passed through at all if unchecked.[/quote] This is incorrect http://ellislab.com/forums/viewreply/380464/ |