Table of Contents
Questions & Feedback
Found a typo or an error?
Want to improve this document? Edit it.
Need support or have a technical question?
Post to the user mailing-list.
Attribution-Share Alike 3.0
form Field Type¶
form type predefines a couple of options that are then available
on all fields.
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:
1 2 3
$builder->add('token', 'hidden', array( 'data' => 'abcdef', ));
If true, an HTML5 required attribute will be rendered. The corresponding
label will also render with a
This is superficial and independent from validation. At best, if you let Symfony guess your field type, then the value of this option will be guessed from your validation information.
type: array or
type: Boolean default: false
Set this option to
true to force validation on embedded form types.
For example, if you have a
ProductType with an embedded
ProductType will cause
the data from
CategoryType to also be validated.
Instead of using this option, you can also use the
Valid constraint in
your model to force validation on a child object stored on a property.
If this option is true, the field will be rendered with the
attribute so that the field is not editable.
If you don't want a user to modify the value of a field, you can set the disabled option to true. Any submitted value will be ignored.
If true, the whitespace of the submitted string value will be stripped
trim() function when the data is bound. This guarantees that
if a value is submitted with extra whitespace, it will be removed before
the value is merged back onto the underlying object.
If you wish the field to be ignored when reading or writing to the object, you
can set the
mapped option to
the field's value
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 do it the way
type: array default: Empty array
If you want to add extra attributes to the HTML field representation,
you can use
attr option. It's an associative array with HTML attribute
as a key. This can be useful when you need to set a custom class for some widget:
1 2 3
$builder->add('body', 'textarea', array( 'attr' => array('class' => 'tinymce'), ));
This is the translation domain that will be used for any labels or options that are rendered for this field.