Checkboxes |
[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.
[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
[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.
[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?)
[eluser]Seppo[/eluser]
isset won't work on expressions, only does with variables Code: // you can't
[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.
[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/ |
Welcome Guest, Not a member yet? Register Sign In |