Using Form Types¶
In this article we will show what types you can use when creating or editing forms, what options they have and what they do.
We use two types of naming for form types:
*FormType- This type is used in Controllers to create forms and their views on front-end or they are used in other FormTypes as sub-forms*Type- This type is used only in other FormTypes to ease adding fields with their own widgets and to add to their reusability
Default options¶
Every form type has some default options that can be used for various things.
renders_in_own_card¶
Controls how form fields are grouped into visual cards in the administration interface.
Default value¶
falsefor most form typestrueforGroupTypeand other specialized container types
Behavior¶
When set to false (default):
Fields are automatically grouped with adjacent fields into shared "auto cards". Consecutive fields without this option will be rendered together in a single card container.
When set to true:
The field breaks the auto-grouping sequence and is rendered separately.
For types like GroupType, this means they render in their own styled card section.
Visual impact¶
In the administration interface, auto cards are rendered as Bootstrap card components (<div class="card mb-3">).
This automatic grouping helps organize forms visually without requiring manual card creation.
When to use¶
You typically don't need to set this option explicitly, as the defaults work well:
- Use
GroupTypewhen you want a labeled section in its own card - Regular fields will automatically group together visually
- Only override this option if you need custom grouping behavior
Form types¶
We created some form types which can help you with creating your own form types. Here you can find an information about what they do and what options they have.
GroupType¶
GroupType is used for creating groups of containers.
It is not mapped onto any property and it inherits data into group so you can work with forms in this group the same way as you were before.
GroupType makes sure to render your fields into nicely styled div wrapper.
GroupType comes with a few options that you can use for even more comfortable work.
label¶
This option is used for displaying heading of section, for example, in CustomerFormType all user data like name, last name or email address are all in section with label Personal Data.
DisplayOnlyCustomerType¶
Displays name of a registered customer along with a link to his/her detail.
If there is no customer set, unregistered customer text will be displayed instead.
DisplayOnlyType¶
Sometimes form needs to only display information but does not need to change and persist this data, for this usages
there is DisplayOnlyType which does not map property onto entity and let you to display your own data.
DisplayOnlyUrlType¶
Displays custom URL based on routing system.
OrderItemsType¶
Displays editable table of OrderItems from provided Order.
MessageType¶
Displays highlighted message with an icon. Allows set the info or warning formatting using the message_level option.
LocalizedType¶
Compound type that renders one form of given type for each locale. Returns array indexed by locale.
entry_type¶
Defaults to TextType::class.
It’s used to define what FormType should be used for the inner forms.
entry_options¶
An array of options that is used for every inner form.
main_constraints¶
An array of constraints that is used for field with the same locale as administration.
CategoriesType¶
Displays a tree of all categories for given domain_id with checkboxes for each category created by CategoryCheckBoxType and returns array indexed by checked category ids.
domain_id¶
Required option that defines for what domain should the categories be listed.
CategoryCheckboxType¶
Creates checkbox and label with category name if name of the form is the same as category id.
Adds visible, category_name, has_children and level vars from category on domain for given domain_id to FormView so you can easily work with the checkbox.
domain_id¶
Required option that defines from what domain should the category be listed.
ColorPickerType¶
Displays text field with box of given color that shows color picker when clicked.
DatePickerType¶
Displays field that shows date picker when clicked.
Value is internally converted from admin display timezone to UTC, so it have to be persisted in database also as DateTime to avoid possible date shifting.
format¶
Defaults to DatePickerType::FORMAT_PHP.
Defines in what format should be the date shown.
DatePickerType has 2 constants that can be used:
- FORMAT_PHP = 'dd.MM.yyyy'
- FORMAT_JS = 'dd.mm.yy'
DateTimeType¶
Displays a text field that allows to set date and time.
Value is internally converted from admin display time zone to UTC.
format¶
Defaults to DateTimeType::FORMAT_PHP.
Defines in what format should be the date shown.
DatePickerType has constant that can be used:
- FORMAT_PHP = 'dd.MM.yyyy HH:mm:ss'
DisplayOnlyDomainIconType¶
Displays domain icon with the domains name for given domain ID in data option.
DomainsType¶
Displays list of non-required checkboxes for every domain with the domain name as label.
DomainType¶
Displays select box with all domain names or domain URLs.
displayUrl¶
Defaults to false.
If you set this option to true, domain url will be shown instead of domain name.
limit_domains_by_ids¶
Limits list of displayed domains to provided ids.
FileUploadType¶
Uses AbstractFileUploadType to display a widget for files upload and to work with them (similar as ImageUploadType).
After a file or files are uploaded it shows box for every file and lets you to downloads, order or delete files.
file_constraints¶
An array of constraints that should be applied for the uploaded file.
file_entity_class¶
Defines which entity class (defined in uploaded_files.yaml) should the files be assigned to.
file_type¶
Defines which type of file (defined in uploaded_files.yaml) should the files be assigned to.
info_text¶
Required option that needs to be string or null and is a text that is shown under the upload icon.
entity¶
Defines which entity should the files be assigned to.
MultiLocaleFileUploadType¶
Extends FileUploadType with additional support for translated file names.
BasicFileUploadType¶
Uses AbstractFileUploadType to display a widget for file uploads and manage them without associating them with any entity.
multiple¶
Allows multiple files to be uploaded.
allow_filenames_input¶
Allows to input custom filenames for uploaded files.
MultiLocaleBasicFileUploadType¶
Extends BasicFileUploadType with additional support for translated file names.
FriendlyUrlType¶
Displays a select box with domain urls and text field that lets you to create friendly url on selected domain with your valid slug.
Uses DomainType to display select box with domain urls.
limit_domains_by_ids¶
Limits list of displayed domains to provided ids.
UrlListType¶
Uses FriendlyUrlType to display a list of friendly URLs for each domain that lets you delete and create friendly URLs with unique slugs and select which URL should be the main for the domain.
route_name¶
Defines which route should the URLs go into.
entity_id¶
Defines what is the entity ID that the URLs are assigned to.
limit_domains_by_ids¶
Limits list of displayed domains to provided ids.
ImageUploadType¶
Uses AbstractFileUploadType to display a widget for images upload and to work with them (same as FileUploadType).
entity¶
Defines which entity should the images be assigned to.
OrderListType¶
Displays a list of orders for given user.
The list contains order number, created on, billing address, delivery address, total price including VAT, status and a link to order detail.
Displays text Customer has no orders so far. if User doesn't have any orders.
user¶
Required option that defines for what user should the orders be listed.
ProductsType¶
Displays a list of products.
The widget adds button that after clicking opens a popup window that lets you to search and to pick products except for main_product.
After picking you can sort or delete picked products.
allow_add¶
Boolean option that defines if products can be added to the list.
allow_delete¶
Boolean option that defines if products can be removed from the list.
sortable¶
Boolean option that defines if products in the list can be sorted.
allow_main_variants¶
Boolean option that defines if main variants can be added.
allow_variants¶
Boolean option that defines if variants can be added.
main_product¶
Option that defines for what product are you picking products. main_product can't be picked.
label_button_add¶
Option that defines text of button for adding products.
ProductType¶
Displays a widget that lets you to pick one product.
It has one input with placeholder or name of picked product and a button that after clicking opens a popup window that lets you to search and to pick a product.
placeholder¶
Option that lets you to add a placeholder text when you dont have picked product.
allow_delete¶
Boolean option that defines if product can be deleted.
allow_main_variants¶
Boolean option that defines if main variants can be picked.
allow_variants¶
Boolean option that defines if variants can be picked.
RolesType¶
Displays a grid of roles with permission checkboxes for managing user permissions in administration. The form type renders roles organized by sections (when grouped) with columns for different permission levels (VIEW, CREATE, EDIT, DELETE, or simplified VIEW/FULL).
context¶
Required option that defines which context roles should be displayed from.
Must be a class-string of a context (e.g., AdminContext::class).
For more information about contexts, see Context System.
excluded_roles¶
Defaults to all system roles (SystemRole::getAll()).
Array of role constants that should be excluded from the display.
Typically used to exclude system roles like ROLE_ALL, ROLE_ALL_VIEW, etc.
simple_permissions¶
When true, only displays VIEW and FULL permissions.
When false, displays all granular permissions (VIEW, CREATE, EDIT, DELETE).
grouped¶
Defaults to true.
When true, roles are organized into sections (e.g., "Orders & Customers", "Products & Catalog").
When false, all roles are displayed in a single ungrouped list.
Example Usage¶
$builder->add('roles', RolesType::class, [
'context' => AdminContext::class,
'excluded_roles' => [SystemRole::ALL, SystemRole::ALL_VIEW],
'simple_permissions' => true,
'grouped' => true,
]);
SingleCheckboxChoiceType¶
Displays a list of choices shown as checkboxes.
SortableValuesType¶
Displays a list of values that lets you add values from a select box, remove them form the list or sort them as you like. Returns array with sorted IDs that have been picked and sorted.
allow_add¶
Boolean option that defines if products can be added to the list.
allow_delete¶
Boolean option that defines if products can be removed from the list.
MultidomainType¶
Compound type that renders one form of given type for each domain. The data of the inner forms are returned as an array indexed by the domain ID.
entry_type¶
Defaults to TextType::class.
The type of the inner form.
entry_options¶
Defaults to [].
The options of the inner forms.
options_by_domain_id¶
Defaults to [].
The options of the inner forms based on the domain ID.
Provide arrays indexed by the domain ID, values are merged with the entry_options.
YesNoType¶
Natural looking choice type for boolean value inputs. A boolean value is accepted/returned as data. A null value can be accepted/returned when no radio button is checked.
ActionBarType¶
The ActionBarType form type provides a standardized action bar, rendered at the bottom of the page, with the "Back" link and the "Save" button.
Available Options¶
| Option | Type | Default Value | Description |
|---|---|---|---|
back_route |
string|null |
null |
Symfony route name for the back button. Cannot be used with back_url. |
back_url |
string|null |
null |
Absolute or relative URL for the back button. Cannot be used with back_route. |
back_label |
string |
t('Back to overview') |
Label for the back button. |
save_label |
string|null |
null |
Label for the save button. Defaults to "Save changes" if entity is set, otherwise "Create". |
entity |
object|null |
null |
The entity associated with the form. Used to determine the save button label. |
mapped |
bool |
false |
Always set to false. |
Constraints¶
- If
back_routeis set,back_urlmust benull, and vice versa.
Form Fields¶
back_link (Optional)¶
- Type:
LinkType - Added when: Either
back_routeorback_urlis set - Label: Set from
back_label
save¶
- Type:
SubmitType - Label:
"Save changes"ifentityis notnull"Create"otherwise- Can be overridden using
save_label
Example Usages¶
Most common usage¶
final class MyEntityFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, ['label' => t('Name')])
->add('actionBar', ActionBarType::class, [
'back_route' => 'admin_myentity_list',
'entity' => $options['my_entity'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setRequired('my_entity')
->setAllowedTypes('my_entity', [MyEntity::class, 'null'])
->setDefaults([
'data_class' => MyEntityData::class,
'attr' => ['novalidate' => 'novalidate'],
]);
}
Adding another item to the action bar¶
$actionBar = $builder->create('actionBar', ActionBarType::class, [
'back_route' => 'admin_myentity_list',
'entity' => $options['my_entity'],
]);
$actionBar->add('createAndDownloadCsv', SubmitType::class, [
'label' => 'Create and download CSV',
'position' => [
'before' => 'save',
],
]);
$builder->add($actionBar);
Note
For information about position option see FormExtension
Form Input Symbols¶
The administration form theme provides a convenient way to add symbols or text before or after form input fields using Bootstrap input groups.
This feature works with any form widget that extends the form_widget_simple block.
Available Symbol Options¶
| Option | Description | HTML Escaping |
|---|---|---|
symbolAfterInput |
Adds text or symbol after the input field | Escaped (safe for plain text) |
symbolBeforeInput |
Adds text or symbol before the input field | Escaped (safe for plain text) |
rawSymbolAfterInput |
Adds HTML content after the input field | Unescaped (allows HTML) |
rawSymbolBeforeInput |
Adds HTML content before the input field | Unescaped (allows HTML) |
Usage Examples¶
Currency Symbols¶
{{ form_widget(form.price, { symbolAfterInput: currencySymbolByDomainId(domainId) }) }}
Unit Symbols¶
{{ form_widget(form.vatPercent, { symbolAfterInput: '%' }) }}
{{ form_widget(form.weight, { symbolAfterInput: 'g'|trans }) }}
HTML Icons (using raw variants)¶
{{ form_widget(form.field, { rawSymbolAfterInput: info_icon('Help text') }) }}
Multiple Symbols¶
{{ form_widget(form.priceRange, {
symbolBeforeInput: '$',
symbolAfterInput: 'USD'
}) }}