- Status changed to Needs review
about 1 year ago 1:45pm 20 April 2024 - last update
about 1 year ago 2,179 pass - 🇮🇳India keshav patel
Updated the #8 patch, the patch on #10 applies cleanly. please review.
- Merge request !7622Issue #1195306: Values for checkboxes in form_state do not match input → (Open) created by apaderno
- last update
about 1 year ago 2,094 pass, 110 fail - 🇮🇹Italy apaderno Brescia, 🇮🇹
I created a MR with the same changes in the patch in comment #7.
- last update
about 1 year ago 2,094 pass, 94 fail - last update
about 1 year ago 2,179 pass - last update
about 1 year ago Patch Failed to Apply - 🇮🇹Italy apaderno Brescia, 🇮🇹
There is something that is not clear for me, in
form_type_checkbox_value()
.function form_type_checkbox_value($element, $input = FALSE) { if ($input === FALSE) { return isset($element['#default_value']) ? $element['#default_value'] : 0; } else { return isset($input) ? $element['#return_value'] : 0; } }
isset($input)
would always return TRUE, even whenform_type_checkbox_value()
is called asform_type_checkbox_value($element)
orform_type_checkbox_value($element, NULL)
.
Given thatreturn isset($input) ? $element['#return_value'] : 0;
is only executed when$input
is notFALSE
, why is not that line simplyreturn $element['#return_value'];
? Eventually, if$element['#return_value']
could be not set, that line should bereturn isset($element['#return_value']) ? $element['#return_value'] : 0;
. - Status changed to Needs work
about 1 year ago 6:36am 21 April 2024 - 🇮🇹Italy apaderno Brescia, 🇮🇹
The description of the return value needs to be changed too.
The data that will appear in
$form_state['values']
for this element, or nothing to use the default.form_type_checkbox_value()
always return a value, even if that value is 0. It is not true it can return nothing. That comment cannot be changed to or nothing to use the default either. That would contrast with the comment inside
form_type_checkbox_value()
, which contains the following sentence.Returning NULL from a value callback means to use the default value, which is not what is wanted when an unchecked checkbox is submitted, so we use integer 0 as the value indicating an unchecked checkbox.
Furthermore, this comment needs to be changed too, since the code is changed.
// Checked checkboxes are submitted with a value (possibly '0' or ''): // http://www.w3.org/TR/html401/interact/forms.html#successful-controls. // For checked checkboxes, browsers submit the string version of // #return_value, but we return the original #return_value. For unchecked // checkboxes, browsers submit nothing at all, but // _form_builder_handle_input_element() detects this, and calls this // function with $input=NULL. Returning NULL from a value callback means to // use the default value, which is not what is wanted when an unchecked // checkbox is submitted, so we use integer 0 as the value indicating an // unchecked checkbox. Therefore, modules must not use integer 0 as a // #return_value, as doing so results in the checkbox always being treated // as unchecked. The string '0' is allowed for #return_value. The most // common use-case for setting #return_value to either 0 or '0' is for the // first option within a 0-indexed array of checkboxes, and for this, // form_process_checkboxes() uses the string rather than the integer.
we return the original #return_value is not always true, as
$input
is returned for programmatically submitted forms. - last update
about 1 year ago 2,179 pass - Status changed to Needs review
about 1 year ago 9:30am 21 April 2024 - 🇮🇹Italy apaderno Brescia, 🇮🇹
I did not change the other phrase.
Given the context in which it is used (browsers submit the string version of#return_value
, but we return the original#return_value
), it is not necessary to say that also$input
could be returned.