Symfony 5: The Fast Track is the best book to learn
modern Symfony development, from zero to production. +300 pages in full color showing how to
combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.
type: mixed default: Defaults to field of the underlying object (if there is one)
When you create a form, each field initially displays the value of the
corresponding property of the form’s domain object (if an object is bound
to the form). If you want to override the initial value for the form or just
an individual field, you can set it in the data option:
Fields display a property value of the form’s domain object by default. When
the form is submitted, the submitted value is written back into the object.
If you want to override the property that a field reads from and writes to,
you can set the property_path option. Its default value is the field’s
If you wish the field to be ignored when reading or writing to the object
you can set the property_path option to false, but using
property_path for this purpose is deprecated, you should use the
New in version 2.1: Since 2.1, the mapped option has been added for this use-case.
This option allows you to modify the target of a validation error.
Imagine you have a custom method named matchingCityAndZipCode that validates
whether the city and zip code match. Unfortunately, there is no “matchingCityAndZipCode”
field in your form, so all that Symfony can do is display the error on top
of the form.
With customized error mapping, you can do better: map the error to the city
field so that it displays above it: