Hi Daniele,
Bricksforge version: 4.0.2
Bricks version: 2.4
Description:
Since the new server-side required validation (FormsHelper::validate_required_from_structure(),
called in elements/pro-forms/actions/init.php), forms can no longer be submitted if they contain
a required field inside a Bricks element that is hidden on the frontend (_hideElementFrontend).
Such elements are never rendered, so the field can never be filled in. However,
build_form_structure() reads the stored element data without excluding hidden elements, and
collect_required_errors() only skips fields reported in hiddenFields (Pro Forms conditional
logic). Elements hidden by Bricks itself are not reported there, so the submission always fails
with “ is required.”
This worked before the update, so existing forms broke silently after updating.
Steps to reproduce:
- Create a Pro Forms form with a normal field and a radio field set to “Required”.
- Wrap the radio field in a Block and enable “Hide element” (frontend) on that Block.
- Submit the form on the frontend.
Expected:
The form submits. Fields inside elements hidden on the frontend are ignored by the
required check, the same way as fields hidden by conditional logic.
Actual:
Submission is rejected with “ is required.” for the hidden field.
Affects all users, including administrators.
Suggested fix:
Skip elements (and their children) with settings[‘_hideElementFrontend’] when building the
form structure or in collect_required_errors().
Workaround:
Remove the “Required” setting from fields inside hidden elements.
Cheers
Marco