form-types-validation
Installation
SKILL.md
Form Types Validation (Symfony)
Use when
- Building or changing a Symfony form type.
- Adding validation constraints on an entity, a DTO, or a form field.
- Different rules per context (registration vs profile) through validation groups.
- Converting values with a data transformer or reacting with form events.
- Writing a custom constraint, or a form spread across several steps.
Default workflow
- Put business constraints on the entity or DTO; keep form-level constraints for UI-only rules such as uploads.
- Build the form type with explicit field types and options.
- Split rules into validation groups when contexts differ.
- Add data transformers or
PRE_SET_DATA/PRE_SUBMITlisteners only where the model and the view disagree. - In the controller, check
isSubmitted() && isValid()and pass the form itself torender().