Skip to content

[Form] Documented legacy_error_messages #14577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,49 @@ To see the second approach - adding constraints to the form - and to
learn more about the validation constraints, please refer to the
:doc:`Symfony validation documentation </validation>`.

.. versionadded:: 5.2

Validation messages for forms have been rewritten to be more user-friendly.
These newer messages can be enabled by setting the `legacy_error_messages`
option to "false". Details about these messages can be found in the corresponding
form type documentation.

.. configuration-block::

.. code-block:: yaml

# config/packages/framework.yaml
framework:
form:
legacy_error_messages: false

.. code-block:: xml

<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:form legacy-error-messages="false"/>
</framework:config>
</container>

.. code-block:: php

// config/packages/framework.php
$container->loadFromExtension('framework', [
'form' => [
'legacy-error-messages' => false,
],
]);


Other Common Form Features
--------------------------

Expand Down
86 changes: 45 additions & 41 deletions reference/forms/types/birthday.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,57 @@ This type is essentially the same as the :doc:`DateType </reference/forms/types/
type, but with a more appropriate default for the `years`_ option. The `years`_
option defaults to 120 years ago to the current year.

+----------------------+-------------------------------------------------------------------------------+
| Underlying Data Type | can be ``DateTime``, ``string``, ``timestamp``, or ``array`` |
| | (see the :ref:`input option <form-reference-date-input>`) |
+----------------------+-------------------------------------------------------------------------------+
| Rendered as | can be three select boxes or 1 or 3 text boxes, based on the `widget`_ option |
+----------------------+-------------------------------------------------------------------------------+
| Overridden options | - `years`_ |
+----------------------+-------------------------------------------------------------------------------+
| Inherited options | from the :doc:`DateType </reference/forms/types/date>`: |
| | |
| | - `choice_translation_domain`_ |
| | - `days`_ |
| | - `placeholder`_ |
| | - `format`_ |
| | - `input`_ |
| | - `input_format`_ |
| | - `model_timezone`_ |
| | - `months`_ |
| | - `view_timezone`_ |
| | - `widget`_ |
| | |
| | from the :doc:`FormType </reference/forms/types/form>`: |
| | |
| | - `attr`_ |
| | - `data`_ |
| | - `disabled`_ |
| | - `help`_ |
| | - `help_attr`_ |
| | - `help_html`_ |
| | - `inherit_data`_ |
| | - `invalid_message`_ |
| | - `invalid_message_parameters`_ |
| | - `mapped`_ |
| | - `row_attr`_ |
+----------------------+-------------------------------------------------------------------------------+
| Parent type | :doc:`DateType </reference/forms/types/date>` |
+----------------------+-------------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\BirthdayType` |
+----------------------+-------------------------------------------------------------------------------+
+---------------------------+-------------------------------------------------------------------------------+
| Underlying Data Type | can be ``DateTime``, ``string``, ``timestamp``, or ``array`` |
| | (see the :ref:`input option <form-reference-date-input>`) |
+---------------------------+-------------------------------------------------------------------------------+
| Rendered as | can be three select boxes or 1 or 3 text boxes, based on the `widget`_ option |
+---------------------------+-------------------------------------------------------------------------------+
| Overridden options | - `invalid_message`_ |
| | - `years`_ |
+---------------------------+-------------------------------------------------------------------------------+
| Inherited options | from the :doc:`DateType </reference/forms/types/date>`: |
| | |
| | - `choice_translation_domain`_ |
| | - `days`_ |
| | - `placeholder`_ |
| | - `format`_ |
| | - `input`_ |
| | - `input_format`_ |
| | - `model_timezone`_ |
| | - `months`_ |
| | - `view_timezone`_ |
| | - `widget`_ |
| | |
| | from the :doc:`FormType </reference/forms/types/form>`: |
| | |
| | - `attr`_ |
| | - `data`_ |
| | - `disabled`_ |
| | - `help`_ |
| | - `help_attr`_ |
| | - `help_html`_ |
| | - `inherit_data`_ |
| | - `invalid_message_parameters`_ |
| | - `mapped`_ |
| | - `row_attr`_ |
+---------------------------+-------------------------------------------------------------------------------+
| Default `invalid_message` | Please enter a valid birthdate. |
+---------------------------+-------------------------------------------------------------------------------+
| Legacy `invalid_message` | The value {{ value }} is not valid. |
+---------------------------+-------------------------------------------------------------------------------+
| Parent type | :doc:`DateType </reference/forms/types/date>` |
+---------------------------+-------------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\BirthdayType` |
+---------------------------+-------------------------------------------------------------------------------+

.. include:: /reference/forms/types/options/_debug_form.rst.inc

Overridden Options
------------------

.. include:: /reference/forms/types/options/invalid_message.rst.inc

``years``
~~~~~~~~~

Expand Down Expand Up @@ -128,8 +134,6 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:

.. include:: /reference/forms/types/options/inherit_data.rst.inc

.. include:: /reference/forms/types/options/invalid_message.rst.inc

.. include:: /reference/forms/types/options/invalid_message_parameters.rst.inc

.. include:: /reference/forms/types/options/mapped.rst.inc
Expand Down
63 changes: 35 additions & 28 deletions reference/forms/types/checkbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,39 @@ you can specify an array of values that, if submitted, will be evaluated
to "false" as well (this differs from what HTTP defines, but can be handy
if you want to handle submitted values like "0" or "false").

+-------------+------------------------------------------------------------------------+
| Rendered as | ``input`` ``checkbox`` field |
+-------------+------------------------------------------------------------------------+
| Options | - `false_values`_ |
| | - `value`_ |
+-------------+------------------------------------------------------------------------+
| Overridden | - `compound`_ |
| options | - `empty_data`_ |
+-------------+------------------------------------------------------------------------+
| Inherited | - `attr`_ |
| options | - `data`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `help`_ |
| | - `help_attr`_ |
| | - `help_html`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `required`_ |
| | - `row_attr`_ |
+-------------+------------------------------------------------------------------------+
| Parent type | :doc:`FormType </reference/forms/types/form>` |
+-------------+------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\CheckboxType` |
+-------------+------------------------------------------------------------------------+
+---------------------------+------------------------------------------------------------------------+
| Rendered as | ``input`` ``checkbox`` field |
+---------------------------+------------------------------------------------------------------------+
| Options | - `false_values`_ |
| | - `value`_ |
+---------------------------+------------------------------------------------------------------------+
| Overridden options | - `compound`_ |
| | - `empty_data`_ |
| | - `invalid_message`_ |
+---------------------------+------------------------------------------------------------------------+
| Inherited options | - `attr`_ |
| | - `data`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `help`_ |
| | - `help_attr`_ |
| | - `help_html`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `required`_ |
| | - `row_attr`_ |
+---------------------------+------------------------------------------------------------------------+
| Default `invalid_message` | The checkbox has an invalid value. |
+---------------------------+------------------------------------------------------------------------+
| Legacy `invalid_message` | The value {{ value }} is not valid. |
+---------------------------+------------------------------------------------------------------------+
| Parent type | :doc:`FormType </reference/forms/types/form>` |
+---------------------------+------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\CheckboxType` |
+---------------------------+------------------------------------------------------------------------+

.. include:: /reference/forms/types/options/_debug_form.rst.inc

Expand Down Expand Up @@ -74,6 +79,8 @@ Overridden Options

.. include:: /reference/forms/types/options/checkbox_empty_data.rst.inc

.. include:: /reference/forms/types/options/invalid_message.rst.inc

Inherited Options
-----------------

Expand Down
Loading