Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If an empty (null) value is submitted, it could be because no elements should be selected.
I believe form_type_multiselect_value should be more in line with form_type_select_value:
function form_type_select_value($element, $input = FALSE) {
if ($input !== FALSE) {
if (isset($element['#multiple']) && $element['#multiple']) {
// If an enabled multi-select submits NULL, it means all items are
// unselected. A disabled multi-select always submits NULL, and the
// default value should be used.
if (empty($element['#disabled'])) {
return (is_array($input)) ? drupal_map_assoc($input) : array();
}
else {
return (isset($element['#default_value']) && is_array($element['#default_value'])) ? $element['#default_value'] : array();
}
}
// Non-multiple select elements may have an empty option preprended to them
// (see form_process_select()). When this occurs, usually #empty_value is
// an empty string, but some forms set #empty_value to integer 0 or some
// other non-string constant. PHP receives all submitted form input as
// strings, but if the empty option is selected, set the value to match the
// empty value exactly.
elseif (isset($element['#empty_value']) && $input === (string) $element['#empty_value']) {
return $element['#empty_value'];
}
else {
return $input;
}
}
}
I will work on a patch tomorrow.
Comment | File | Size | Author |
---|---|---|---|
#2 | submitting_an_empty-2742981-2.patch | 440 bytes | daften |
Comments
Comment #2
daften CreditAttribution: daften at Picabit commentedPatch in attachment
Comment #3
daften CreditAttribution: daften at Picabit commentedSetting to needs review
Comment #4
cosolom CreditAttribution: cosolom commentedWorked for me in FAPI mode. Thanks.