diff --git a/reference/forms/types/color.rst b/reference/forms/types/color.rst index e85fee1e2ff..34591f58f9f 100644 --- a/reference/forms/types/color.rst +++ b/reference/forms/types/color.rst @@ -56,11 +56,11 @@ These options inherit from the :doc:`FormType `: .. 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 diff --git a/reference/forms/types/email.rst b/reference/forms/types/email.rst index e27898386d4..a937b97fee8 100644 --- a/reference/forms/types/email.rst +++ b/reference/forms/types/email.rst @@ -37,11 +37,11 @@ These options inherit from the :doc:`FormType `: .. 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 diff --git a/reference/forms/types/options/text_empty_data_declaration.rst.inc b/reference/forms/types/options/text_empty_data_declaration.rst.inc new file mode 100644 index 00000000000..4db2aa6723e --- /dev/null +++ b/reference/forms/types/options/text_empty_data_declaration.rst.inc @@ -0,0 +1,4 @@ +``empty_data`` +~~~~~~~~~~~~~~ + +**type**: ``mixed`` diff --git a/reference/forms/types/options/text_empty_data_description.rst.inc b/reference/forms/types/options/text_empty_data_description.rst.inc new file mode 100644 index 00000000000..69c594d2812 --- /dev/null +++ b/reference/forms/types/options/text_empty_data_description.rst.inc @@ -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. diff --git a/reference/forms/types/password.rst b/reference/forms/types/password.rst index d512be22594..407b0276acb 100644 --- a/reference/forms/types/password.rst +++ b/reference/forms/types/password.rst @@ -59,11 +59,11 @@ These options inherit from the :doc:`FormType `: .. 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 diff --git a/reference/forms/types/range.rst b/reference/forms/types/range.rst index 3d8730ed249..dda85c3b07c 100644 --- a/reference/forms/types/range.rst +++ b/reference/forms/types/range.rst @@ -52,11 +52,11 @@ These options inherit from the :doc:`FormType `: .. 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 diff --git a/reference/forms/types/search.rst b/reference/forms/types/search.rst index 048dd535ab5..d1ab974cb52 100644 --- a/reference/forms/types/search.rst +++ b/reference/forms/types/search.rst @@ -37,11 +37,11 @@ These options inherit from the :doc:`FormType `: .. 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 diff --git a/reference/forms/types/tel.rst b/reference/forms/types/tel.rst index 8a99b6752c5..9587b8e884b 100644 --- a/reference/forms/types/tel.rst +++ b/reference/forms/types/tel.rst @@ -43,11 +43,11 @@ These options inherit from the :doc:`FormType `: .. 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 diff --git a/reference/forms/types/text.rst b/reference/forms/types/text.rst index bf1876a0925..148c37efa9b 100644 --- a/reference/forms/types/text.rst +++ b/reference/forms/types/text.rst @@ -27,13 +27,13 @@ These options inherit from the :doc:`FormType `: .. 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 diff --git a/reference/forms/types/textarea.rst b/reference/forms/types/textarea.rst index 413d8e5a09b..c0db7b5ef79 100644 --- a/reference/forms/types/textarea.rst +++ b/reference/forms/types/textarea.rst @@ -40,11 +40,11 @@ These options inherit from the :doc:`FormType `: .. 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 diff --git a/reference/forms/types/url.rst b/reference/forms/types/url.rst index 6a5d368c41c..5069a597f34 100644 --- a/reference/forms/types/url.rst +++ b/reference/forms/types/url.rst @@ -50,11 +50,11 @@ These options inherit from the :doc:`FormType `: .. 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