Symfony 8.2 Improves Form Ranges, Flows, Validation and Choice Fields
- Javier Eguiluz
- 337 reads
Symfony 8.2 adds range forms, nested flow steps and post-validation events, plus better array handling, form attributes and choice help.

Less custom code for ranges and multi-step flows
Symfony 8.2 focuses on form behavior that applications often had to assemble themselves: paired range fields, nested steps, and events that run after validation completes. The practical gains are fewer custom checks and more control over when data is transformed or how fields are presented. Several changes also affect compatibility, especially for custom form themes and event listeners.

The new BoundsType represents a lower and upper value using the same inner form type. A price range can use MoneyType, for example, while a date range can use DateType. Shared settings go in options; from_options and to_options let each bound have its own label or configuration. The child forms are named from and to, mapping to matching array keys or object properties. Models with names such as minPrice and maxPrice can map them through each child’s property_path.

Set compare to check that the lower value does not exceed the upper one. Symfony compares scalar values, dates, and enums in their declared order; other types need a comparison callable. A failed check is attached to the lower field, where a user can adjust the range. That packages a common validation rule with the paired inputs instead of requiring each application to recreate it.

Multi-step form flows can now nest steps. The new createStepGroup() method creates a structural group, such as a “flights” step containing outbound and return steps. A group has no rendered form of its own, so navigation proceeds directly to its children. Calling setSkip() on a step can also skip that step and all its descendants based on submitted data. The hierarchy changes flow structure and navigation, while all steps continue to write to the same underlying object.

Events that match the full validation lifecycle
Before 8.2, a child form’s POST_SUBMIT event ran before the root form completed validation. A listener on that child therefore couldn’t reliably inspect the final validity of the whole form. The new FormEvents::POST_VALIDATE event, also named form.post_validate, runs on every form in the tree after validation has finished. Reusable types can use it for follow-up behavior that depends on the root form’s result, such as resetting a CAPTCHA when the form will be shown again. Application controllers should still check isValid() after handleRequest().

Symfony now uses this event to hash password fields configured with hash_property_path. That change deprecates FormTypePasswordHasherExtension and the registerPassword() and hashPasswords() methods on PasswordHasherListener; they are slated for removal in Symfony 9.0. Teams with custom integrations around those APIs should plan to move to the newer behavior before upgrading.

More control over submitted data and rendered HTML
Scalar form fields normally reject array input before dispatching PRE_SUBMIT, which blocks listeners from converting structured payloads such as JSON into a scalar value. The new allow_array_submission option lets those listeners receive the array first. For example, a listener can turn a list of tags into a comma-separated string. The option defaults to false; when enabled, every PRE_SUBMIT listener on that field must be prepared for array data. A listener that runs before the form type’s own listeners needs a priority above zero. If the value remains an array after listeners finish, submission still fails as before.

The form_attr option now points fields rendered outside the form element to the actual <form> ID. Previously, it referenced the wrapping <div>, so the HTML association did not work. Symfony 8.2 renders a form ID when a field uses this option; forms that don’t use it keep their previous output. Applications can set a different ID through the root form’s attr option. Custom themes that override form_start should render the new form_id variable. The root form’s name attribute can also now be overridden or removed through attr.
Choice fields gain clearer guidance and sorting
Choice fields can now show help text for each individual option through choice_help. Like choice_label, it accepts an array, callable, or property path. Expanded choices render the help beside each radio button or checkbox and connect it to the input with aria-describedby. Symfony translates the text with choice_translation_domain. A collapsed <select> cannot show this help because HTML option elements can’t contain nested content.
The sort_choices option sorts choices by their translated labels using the current locale. This can make enum values easier to scan when their declaration order isn’t useful. Sorting relies on PHP’s intl extension and its Collator class, which handles accents, letter case, and numeric portions so “Level 2” precedes “Level 10.” Choice groups and preferred choices are sorted as well.
For teams upgrading, the main review points are the password hasher deprecations, custom form_start themes, and listeners that opt into array submissions. The rest of the changes target recurring form work: range validation, structured navigation, per-choice guidance, and locale-aware ordering.