I’m trying to alter a checked checkbox using hook_form_alter with this:
$form['foo']['#attributes'] = array();
and/or
$form['foo']['#default_value'] = '0';
Basically the current output of the form is this:
[foo] => array (
[#type] => [checkbox]
[#attributes] => array (
[checked] => [checked]
)
)
This is a checkbox that is checked by default. Now I want to uncheck the box and save it as that.
I managed to uncheck the box by default but that value does not save at all. Form is still being submitted with the checkbox checked.
What am I missing?
Try this $form[‘foo’][‘#default_value’] = array(‘0’);
The default value for checkbox is always an array of values. Remember its value and not the string displayed on the form.