New in Symfony 4.3: Form improvements
February 20, 2019 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Added a Twig function to get the parent form
Contributed by
Christian Flothmann
in #28812.
In Symfony 4.3 we added a Twig function called form_parent()
which returns
the parent form view or null
if the form view already is the root form.
Using this function should be preferred over accessing the parent form using
form.parent
. The latter way will produce different results for example when
a child form is named parent
.
Allow including HTML contents in help messages
Contributed by
Mathieu Piot
in #29861.
The contents of the help
message that can be defined for form fields are
escaped by default to prevent security issues. If your help messages contain
HTML elements (e.g. links to other pages) and you know they are safe to render
"as is", set to true
the new help_html
option added in Symfony 4.3:
1 2 3 4
$builder->add('zip_code', null, [
'help' => '<a target="_blank" href="...">Look up your ZIP code.</a>',
'help_html' => true,
]);
Configure the input format of DateType and DateTimeType
Contributed by
Thomas Calvet
in #29887.
In Symfony 4.3 we added a new input_format
option to DateType
and
DateTimeType
. If the input
option is set to string
, this option
specifies the format of the date, which must be a valid PHP date format.
1 2 3 4 5 6 7
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
$builder->add('startsAt', DateTimeType::class, [
// ...,
'input' => 'string',
'input_format' => 'm-d H:i',
]);
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Finally an end to custom form types that follow Y-m-d [H:i:s] or something similar via awkward configs
Thanks a bunch!