@@ -9,20 +9,23 @@ empty_data
9
9
10
10
DEFAULT_PLACEHOLDER
11
11
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
13
13
value 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.
16
15
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``
19
18
when no value is selected, you can do it like this::
20
19
21
20
$builder->add('name', null, array(
22
- 'required' => false,
23
- 'empty_data' => 'John Doe',
21
+ 'required' => false,
22
+ 'empty_data' => 'John Doe',
24
23
));
25
24
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
+
26
29
If a form is compound, you can set ``empty_data`` as an array with field names
27
30
as keys and submitted values as string values (or arrays if nested fields are
28
31
also compound).
@@ -34,6 +37,7 @@ also compound).
34
37
35
38
.. caution::
36
39
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