Skip to content

Commit

Permalink
[BUGFIX] Handle empty values with FormEngine radio fields
Browse files Browse the repository at this point in the history
The bug report #102303 indicates that a TCA element type=radio
with items containing an empty string do not get properly
restored/persisted in FormEngine (Backend GUI input fields).

This is because empty attributes from HTML `<input>` fields are
not evaluated, and thus not restored and stored properly when
selected. `GeneralUtility::implodeAttributes()` calls do not
utilize the `keepBlankAttributes` parameter.

The report specifically mentions radio Element types, but also
effects checkboxes and `<option>` tags. An option tag without
a value submits the label of the option instead of an empty
value, so the attribute `value=""` is important.

The `CategoryElement` and `JsonElement` both already use
the parameter `keepBlankAttributes`, so the older FormEngine
Elements were probably not re-investigated.

See #102303 on details how to test this patch.

Docs [1] currently do not mention that "value" may not be
an empty string.

[1] https://docs.typo3.org/m/typo3/reference-tca/main/en-us/ColumnsConfig/Type/Radio/Properties/Items.html

Resolves: #102303
Releases: main, 12.4
Change-Id: Id6a978c391dfb3781e400361e18810a037fc12a6
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81823
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
  • Loading branch information
fe-hicking authored and lolli42 committed Nov 21, 2023
1 parent 95c41f9 commit f56e035
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion typo3/sysext/backend/Classes/Form/Element/RadioElement.php
Expand Up @@ -103,7 +103,7 @@ public function render()
$radioElementAttrs['checked'] = 'checked';
}
$html[] = '<div class="form-check' . $disabled . '">';
$html[] = '<input ' . GeneralUtility::implodeAttributes($radioElementAttrs, true) . $disabled . '>';
$html[] = '<input ' . GeneralUtility::implodeAttributes($radioElementAttrs, true, true) . $disabled . '>';
$html[] = '<label class="form-check-label" for="' . $radioId . '">';
$html[] = htmlspecialchars($this->appendValueToLabelInDebugMode($label, $value));
$html[] = '</label>';
Expand Down
Expand Up @@ -204,7 +204,7 @@ public function render()

$tableRows[] = '<tr>';
$tableRows[] = '<td class="col-checkbox">';
$tableRows[] = '<input ' . GeneralUtility::implodeAttributes($inputElementAttrs, true) . '>';
$tableRows[] = '<input ' . GeneralUtility::implodeAttributes($inputElementAttrs, true, true) . '>';
$tableRows[] = '</td>';
$tableRows[] = '<td class="col-title">';
$tableRows[] = '<label class="label-block nowrap-disabled" for="' . $item['id'] . '">';
Expand Down
Expand Up @@ -213,7 +213,7 @@ public function render()

foreach ($selectableItemGroup['items'] as $item) {
$selectableItemsHtml[] = '
<option ' . GeneralUtility::implodeAttributes($item['attributes'], true) . '>
<option ' . GeneralUtility::implodeAttributes($item['attributes'], true, true) . '>
' . htmlspecialchars($item['label']) . '
</option>';
}
Expand Down
Expand Up @@ -212,7 +212,7 @@ protected function renderOptionElement($value, $label, array $attributes = [])
{
$attributes['value'] = $value;
$html = [
'<option ' . GeneralUtility::implodeAttributes($attributes, true) . '>',
'<option ' . GeneralUtility::implodeAttributes($attributes, true, true) . '>',
htmlspecialchars($this->appendValueToLabelInDebugMode($label, $value), ENT_COMPAT, 'UTF-8', false),
'</option>',

Expand Down

0 comments on commit f56e035

Please sign in to comment.