I just upgraded to Drupal 7.60 (from 7.59) and now I receive this on my form page is first loaded:

Warning: Invalid argument supplied for foreach() in form_type_checkboxes_value() (line 2390 of /var/www/html/includes/form.inc).

It doesn't appear to affect the operation of the form checkboxes that I can tell so far. I would like to suppress the warning though or fix it in case it does have an issue with the actual form display or function.

Comments

keithgcochran created an issue. See original summary.

keithgcochran’s picture

I've resolved this issue for now by adding a check for an empty array.

form.inc method form_type_checkboxes_value:

WAS:
function form_type_checkboxes_value($element, $input = FALSE) {
if ($input === FALSE) {
$value = array();
$element += array('#default_value' => array());
foreach ($element['#default_value'] as $key) {
$value[$key] = $key;
}
return $value;
}
...

NOW:
function form_type_checkboxes_value($element, $input = FALSE) {
if ($input === FALSE) {
$value = array();
$element += array('#default_value' => array());
if (!empty($element['#default_value'])) { // check for empty array before using
foreach ($element['#default_value'] as $key) {
$value[$key] = $key;
}
}
return $value;
}
...

alex-b’s picture

An empty array is a valid argument for foreach. I suspect your fix works because the #default_value for the affected checkboxes element is set to another 'empty' value somewhere outside form_type_checkboxes_value(), e.g. 0 or FALSE. Can you check the if the element which triggers the warning has a #default_value?

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.