@@ -9,20 +9,23 @@ empty_data
99
1010DEFAULT_PLACEHOLDER
1111
12- This option determines what value the field will return when the submitted
12+ This option determines what value the field will * return* when the submitted
1313value is empty (or missing). It does not set an initial value if none is
14- provided when the form is rendered in a view (see ``data`` or ``placeholder``
15- options).
14+ provided when the form is rendered in a view.
1615
17- It helps you handling form submission and you can customize this to your needs.
18- For example, if you want the ``name`` field to be explicitly set to ``John Doe``
16+ This means it helps you handling form submission with blank fields. For
17+ example, if you want the ``name`` field to be explicitly set to ``John Doe``
1918when no value is selected, you can do it like this::
2019
2120 $builder->add('name', null, array(
22- 'required' => false,
23- 'empty_data' => 'John Doe',
21+ 'required' => false,
22+ 'empty_data' => 'John Doe',
2423 ));
2524
25+ This will still render an empty text box, but upon submission the ``John Doe``
26+ value will be set. Use the ``data`` or ``placeholder`` options to show this
27+ initial value in the rendered form.
28+
2629If a form is compound, you can set ``empty_data`` as an array with field names
2730as keys and submitted values as string values (or arrays if nested fields are
2831also compound).
@@ -34,6 +37,7 @@ also compound).
3437
3538.. caution::
3639
37- When using `empty_data` as an empty string, the form will always return
38- ``null``. If you need to get an empty string to be returned, you should
39- use a data transformer, see the :doc:`/form/data_transformers` article.
40+ :doc:`Form data transformers </form/data_transformers>` will still be
41+ applied to the ``empty_data`` value. This means that an empty string will
42+ be casted to ``null``. Use a custom data transformer if you explicitly want
43+ to return the empty string.
0 commit comments