Bug #100301
closedUndefined array key for form fields of type checkbox
0%
Description
Defining a form like this
type: Form prototypeName: standard identifier: variant-Test label: Newsletter Subscription renderables: - type: Page identifier: page-1 label: General data renderables: - type: Text identifier: email-address label: Email address defaultValue: variants: - identifier: validation-1 condition: 'formValues["checkbox-1"] == 1' properties: fluidAdditionalAttributes: required: required validators: - identifier: NotEmpty - identifier: EmailAddress - type: Checkbox identifier: checkbox-1 label: Check this and email will be mandatory
throws an error when the checkbox is not checked:
PHP Warning: Undefined array key "checkbox-1" in /var/www/html/vendor/symfony/expression-language/Node/GetAttrNode.php line 97
Select fields with empty value option behave probably similar.
I'm not sure if all cases would be covered then.
Updated by Andreas Kienast over 1 year ago
- Status changed from New to Needs Feedback
This is a general issue in the underlying Symfony Expression Language API. We suffer from the same issue in TypoScript conditions, where traverse()
is recommended. Can you please check whether traverse(formValues, "checkbox-1") == true)
works for you?
Updated by Holger McCloy over 1 year ago
Hi Andreas,
since you did not yet get any feedback: I had the same issue and your workaround works.
Thanks!
Updated by Christian Kuhn over 1 year ago
- Status changed from Needs Feedback to Closed
Note for anyone stumbling upon this:
This is not considered a bug, but a limitation / design decision of symfony expression language at this point: Potentially not existing structures need to be sanitized with traverse() (a TYPO3 addition), otherwise it explodes. With objects, the `?` operator can be used as well in TYPO3 v12.
This is similar in TypoScript conditions: TYPO3 v11 catches this with a pretty ugly hack, but TYPO3 v12 lets it explode as well, just like with ext:form form definition conditions.
The "condition" chapter in TypoScript Reference docs has a series of good examples on this, and many of them can be used 1:1 in ext:form form conditions as well.