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
Hello, @yorkshirepudding! Thanks a lot, I got it, all sorted out.
My layout template (layout--blog.tpl.php) doesn't work
Hi @Gnome and welcome to Backdrop When I create custom layout templates I put them in /layouts/custom/my_layout Note: you can split modules and layouts between contrib and custom...
My layout template (layout--blog.tpl.php) doesn't work
This post explains how to do this in Drupal 7. In Backdrop, File Entity is already part of core. You will need to download and install module Views Field View. https://drupal.stackexchange...
I Need to Display an Image in a View that was Uploaded to a Webform