Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f3813d

Browse files
HeahDudewouterj
authored andcommitted
Updated the example add added a caution
1 parent4fd2d96 commit5f3813d

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,30 @@ empty_data
1010
DEFAULT_PLACEHOLDER
1111

1212
This option determines what value the field will return when the submitted
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).
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).
1516

1617
It helps you handling form submission and you can customize this to your needs.
17-
For example, if you want the ``gender``choicefield to be explicitly set to ``Male``
18+
For example, if you want the ``name`` field to be explicitly set to ``John Doe``
1819
when no value is selected, you can do it like this::
1920

20-
$builder->add('gender', 'choice', array(
21-
'choices' => array(
22-
'm' => 'Male',
23-
'f' => 'Female',
24-
),
21+
$builder->add('name', null, array(
2522
'required' => false,
26-
'placeholder' => 'Choose your gender',
27-
'empty_data' => 'm',
23+
'empty_data' => 'John Doe',
2824
));
2925

30-
If a form is compound, you can set ``empty_data`` as an array withfields names
26+
If a form is compound, you can set ``empty_data`` as an array withfield names
3127
as keys and submitted values as string values (or arrays if nested fields are
3228
also compound).
3329

34-
.. caution::
35-
36-
In this example, the choice field is not set as ``multiple``. If it was
37-
``empty_data`` option should be an array of submitted string values::
38-
39-
'empty_data' => array('m'),
40-
4130
.. note::
4231

4332
If you want to set the ``empty_data`` option for your entire form class,
4433
see the :doc:`/form/use_empty_data` article.
34+
35+
.. caution::
36+
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.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp