Skip to content

[Form] String is the preferred value type for TextType #15404

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

Open
wants to merge 1 commit into
base: 6.1
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions reference/forms/types/color.rst
Original file line number Diff line number Diff line change
@@ -56,11 +56,11 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:

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

.. include:: /reference/forms/types/options/empty_data_declaration.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_declaration.rst.inc

The default value is ``''`` (the empty string).

.. include:: /reference/forms/types/options/empty_data_description.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_description.rst.inc

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

4 changes: 2 additions & 2 deletions reference/forms/types/email.rst
Original file line number Diff line number Diff line change
@@ -37,11 +37,11 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:

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

.. include:: /reference/forms/types/options/empty_data_declaration.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_declaration.rst.inc

The default value is ``''`` (the empty string).

.. include:: /reference/forms/types/options/empty_data_description.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_description.rst.inc

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``empty_data``
~~~~~~~~~~~~~~

**type**: ``mixed``
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
This option determines what value the field will *return* when the submitted
value is empty (or missing). It does not set an initial value if none is
provided when the form is rendered in a view.

This means it helps you handling form submission with blank fields. For
example, if you want the ``name`` field to be explicitly set to ``John Doe``
when no value is selected, you can do it like this::

$builder->add('name', null, [
'required' => false,
'empty_data' => 'John Doe',
]);

This will still render an empty text box, but upon submission the ``John Doe``
value will be set. Use the ``data`` or ``placeholder`` options to show this
initial value in the rendered form.

If a form is compound, you can set ``empty_data`` as an array, object or
closure. See the :doc:`/form/use_empty_data` article for more details about
these options.

.. note::

If you want to set the ``empty_data`` option for your entire form class,
see the :doc:`/form/use_empty_data` article.
4 changes: 2 additions & 2 deletions reference/forms/types/password.rst
Original file line number Diff line number Diff line change
@@ -59,11 +59,11 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:

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

.. include:: /reference/forms/types/options/empty_data_declaration.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_declaration.rst.inc

The default value is ``''`` (the empty string).

.. include:: /reference/forms/types/options/empty_data_description.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_description.rst.inc

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

4 changes: 2 additions & 2 deletions reference/forms/types/range.rst
Original file line number Diff line number Diff line change
@@ -52,11 +52,11 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:

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

.. include:: /reference/forms/types/options/empty_data_declaration.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_declaration.rst.inc

The default value is ``''`` (the empty string).

.. include:: /reference/forms/types/options/empty_data_description.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_description.rst.inc

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

4 changes: 2 additions & 2 deletions reference/forms/types/search.rst
Original file line number Diff line number Diff line change
@@ -37,11 +37,11 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:

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

.. include:: /reference/forms/types/options/empty_data_declaration.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_declaration.rst.inc

The default value is ``''`` (the empty string).

.. include:: /reference/forms/types/options/empty_data_description.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_description.rst.inc

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

4 changes: 2 additions & 2 deletions reference/forms/types/tel.rst
Original file line number Diff line number Diff line change
@@ -43,11 +43,11 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:

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

.. include:: /reference/forms/types/options/empty_data_declaration.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_declaration.rst.inc

The default value is ``''`` (the empty string).

.. include:: /reference/forms/types/options/empty_data_description.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_description.rst.inc

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

4 changes: 2 additions & 2 deletions reference/forms/types/text.rst
Original file line number Diff line number Diff line change
@@ -27,13 +27,13 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:

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

.. include:: /reference/forms/types/options/empty_data_declaration.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_declaration.rst.inc

From an HTTP perspective, submitted data is always a string or an array of strings.
So by default, the form will treat any empty string as null. If you prefer to get
an empty string, explicitly set the ``empty_data`` option to an empty string.

.. include:: /reference/forms/types/options/empty_data_description.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_description.rst.inc

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

4 changes: 2 additions & 2 deletions reference/forms/types/textarea.rst
Original file line number Diff line number Diff line change
@@ -40,11 +40,11 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:

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

.. include:: /reference/forms/types/options/empty_data_declaration.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_declaration.rst.inc

The default value is ``''`` (the empty string).

.. include:: /reference/forms/types/options/empty_data_description.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_description.rst.inc

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

4 changes: 2 additions & 2 deletions reference/forms/types/url.rst
Original file line number Diff line number Diff line change
@@ -50,11 +50,11 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:

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

.. include:: /reference/forms/types/options/empty_data_declaration.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_declaration.rst.inc

The default value is ``''`` (the empty string).

.. include:: /reference/forms/types/options/empty_data_description.rst.inc
.. include:: /reference/forms/types/options/text_empty_data_description.rst.inc

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