Skip to content

Commit 87b3542

Browse files
HeahDudewouterj
authored andcommitted
explicit differences between 'data' & 'empty_data' in FormType
1 parent 8292f92 commit 87b3542

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
data
22
~~~~
33

4-
**type**: ``mixed`` **default**: Defaults to field of the underlying object (if there is one)
4+
**type**: ``mixed`` **default**: Defaults to field of the underlying structure.
55

6-
When you create a form, each field initially displays the value of the
7-
corresponding property of the form's domain object (if an object is bound
8-
to the form). If you want to override the initial value for the form or
9-
just an individual field, you can set it in the data option::
6+
When you attach a form type to a form, it becomes a field that initially maps
7+
the value of the corresponding property or key of the form's domain data. If
8+
you want to override the initial value which will be rendered in the view for
9+
the form or any field, you can set it in the data option::
1010

1111
$builder->add('token', 'hidden', array(
1212
'data' => 'abcdef',
@@ -15,5 +15,5 @@ just an individual field, you can set it in the data option::
1515
.. note::
1616

1717
The default values for form fields are taken directly from the underlying
18-
data structure (e.g. an entity or an array). The ``data`` option overrides
19-
this default value.
18+
data structure matching the field name with a property of an object or a
19+
key of an array. The ``data`` option overrides this default value.

reference/forms/types/options/empty_data.rst.inc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ empty_data
1010
DEFAULT_PLACEHOLDER
1111

1212
This option determines what value the field will return when the submitted
13-
value is empty.
13+
value is empty. It does not set an initial value if none is provided when
14+
the form is rendered in a view (see `Data` or `Placeholder` options).
1415

15-
But you can customize this to your needs. For example, if you want the
16-
``gender`` choice field to be explicitly set to ``null`` when no value is
17-
selected, you can do it like this::
16+
It helps you handling form submission and you can customize this to your needs.
17+
For example, if you want the ``gender`` choice field to be explicitly set to ``null``
18+
when no value is selected, you can do it like this::
1819

1920
$builder->add('gender', 'choice', array(
2021
'choices' => array(

0 commit comments

Comments
 (0)