Consider this form element:
$form['my_checkboxes'] = array(
'#type' => 'checkboxes',
'#title' => 'my Checkboxes',
'#options' => array(
1 => 'one',
2 => 'two',
3 => 'three',
4 => 'four',
),
'#default_value' => 2,
);
The above throws the following error:
Warning: Invalid argument supplied for foreach() in form_type_checkboxes_value()
(line ... of /var/www/html/includes/form.inc).
This is because the #default_value
for '#type' => 'checkboxes'
is always expected to be provided in a form of an array. So in order to fix the above, the code should be changed to this instead:
- '#default_value' => 2,
+ '#default_value' => array(2),
This always trips me, and although it makes sense in cases where multiple checkboxes from the #options
need to be ticked, it feels silly to impose on developers when we can fix it for them.
See the following resources: - https://www.drupal.org/project/drupal/issues/3009881 - https://www.drupal.org/project/drupal/issues/1768464 - https://www.drupal.org/forum/support/module-development-and-code-questio...
Recent comments
Tried and successfully applied DrAlbany's method with the form https://www.drupal.org/sandbox/grobot/2105379stickman hook. I also encountered the same situation. Thanks DrAlbany
Ubercart - Auto increment SKU
Since before migration you need to prepare the Drupal site - disabling and removing all modules, disabling themes, as part of the preparation you can clear the cache and logs, delete the search...
Trimming the size of my database for D2B_migrate not to error out (Request Entity Too Large / 504 Gateway Time-out)
QuickTabs is now available!!! But does not work as expected, already reported (https://github.com/backdrop-contrib/quicktabs/issues/14). Maybe an alternative solution using Views...
Quick Tabs (or method to simulate)