$form-checkbox() confusion

There must be something I am missing.

from the documentaion:
$form->checkbox($name, $value, $isChecked, $tagAttributes);
which says $isChecked is of type boolean

in my add.php I've tried...

$form->checkbox('types', $type_video, false);
$form->checkbox('types', $type_video, 0);
$form->checkbox('types', $type_video, 'false');
$form->checkbox('types', $type_video, 'off');
$form->checkbox('types', $type_video);

I'm just trying to uncheck a checkbox. What I am missing?

View Replies: View Best Answer
mkly replied on at Permalink Reply
I must just be going crazy. It it false as the documentation states.

$form->checkbox('types', $type_video, false);
jordanlev replied on at Permalink Best Answer Reply
The problem I always run into with checkboxes is when trying to save the form data. For example, if you're writing a block, you need to handle it specially in your controller's save() method:
public function save($args) {
    $args['your_field_name'] = isset($args['your_field_name']) ? 1 : 0;
mkly replied on at Permalink Reply
I did add that, but I seem to be having issues.

I was having trouble getting the defaults in db.xml to apply so I added
$this->set('type_video', 1);
to my add.php file and the checkbox was displayed 'unchecked' and if I added
$this->set('type_video', 0);
then the checkbox displayed checked. Does that makes sense? It seems to be the reverse of what I would expect.

Also, although I have
function save($args) {
  $args['type_video'] = isset($args['type_video']) ? 1 : 0;

It is being stored as zero in the database

If this helps this is in my db.xml file
<field name="type_regular" type="I1">
  <unsigned />
  <notnull />
  <default value="0" />
mkly replied on at Permalink Reply
After doing some edits
$form->checkbox('type_video', $type_video, false);

The false no longer has any effect.

Honestly, I just want to use a couple checkboxes. I've been looking through some source code and I just can't see what is so different about mine.

And then I end up with this error
Fatal error: Call to a member function getInstance() on a non-object in /var/www/concrete/libraries/database_indexed_search.php on line 137
ssdscott replied on at Permalink Reply
OMG, hours of wrestling with check boxes - "why doesn't the form helper checkbox store a value?" - googling every flavor of the above query, and it's as simple as overriding the save method in the controller.

ACK! I hope this is simpler in 5.7