summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2012-07-29 16:05:06 -0400
committerDavid Rothstein <drothstein@gmail.com>2012-07-29 16:05:06 -0400
commit331a3756c369eb4f08272a7a5721a13fd841dfae (patch)
tree13fcfcf5f498c732bf4f95ee12bb2f6bc4c280c0 /includes
parent568611ec397a2fb663988b04cf9105af68d4a1ba (diff)
downloadbrdo-331a3756c369eb4f08272a7a5721a13fd841dfae.tar.gz
brdo-331a3756c369eb4f08272a7a5721a13fd841dfae.tar.bz2
Issue #811542 by David_Rothstein, attiks, thekevinday, effulgentsia, chx: Fixed Regression: Optional radio buttons with an empty, non-NULL default value led to an illegal choice error when none were selected.
Diffstat (limited to 'includes')
-rw-r--r--includes/form.inc37
1 files changed, 17 insertions, 20 deletions
diff --git a/includes/form.inc b/includes/form.inc
index bea4914b0..12d90053d 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -2351,30 +2351,27 @@ function form_type_tableselect_value($element, $input = FALSE) {
*/
function form_type_radios_value(&$element, $input = FALSE) {
if ($input !== FALSE) {
- // There may not be a submitted value for multiple radio buttons, if none of
- // the options was checked by default. If there is no submitted input value
- // for this element (NULL), _form_builder_handle_input_element()
- // automatically attempts to use the #default_value (if set) or an empty
- // string (''). However, an empty string would fail validation in
- // _form_validate(), in case it is not contained in the list of allowed
- // values in #options.
- if (!isset($input)) {
- // Signify a garbage value to disable the #default_value handling and take
- // over NULL as #value.
- $element['#has_garbage_value'] = TRUE;
- // There was a user submission so validation is a must. If this element is
- // #required, then an appropriate error message will be output. While an
- // optional #type 'radios' does not necessarily make sense from a user
- // interaction perspective, there may be use-cases for that and it is not
- // the job of Form API to artificially limit possibilities.
+ // When there's user input (including NULL), return it as the value.
+ // However, if NULL is submitted, _form_builder_handle_input_element() will
+ // apply the default value, and we want that validated against #options
+ // unless it's empty. (An empty #default_value, such as NULL or FALSE, can
+ // be used to indicate that no radio button is selected by default.)
+ if (!isset($input) && !empty($element['#default_value'])) {
$element['#needs_validation'] = TRUE;
}
- // The value stays the same, but the flags above will ensure it is
- // processed properly.
return $input;
}
- elseif (isset($element['#default_value'])) {
- return $element['#default_value'];
+ else {
+ // For default value handling, simply return #default_value. Additionally,
+ // for a NULL default value, set #has_garbage_value to prevent
+ // _form_builder_handle_input_element() converting the NULL to an empty
+ // string, so that code can distinguish between nothing selected and the
+ // selection of a radio button whose value is an empty string.
+ $value = isset($element['#default_value']) ? $element['#default_value'] : NULL;
+ if (!isset($value)) {
+ $element['#has_garbage_value'] = TRUE;
+ }
+ return $value;
}
}