8000 Merge branch '2.0' · llewellynthomas/symfony-docs@b4c74d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit b4c74d5

Browse files
committed
Merge branch '2.0'
2 parents 8fbc42e + 3c28360 commit b4c74d5

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

book/forms.rst

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ corresponding errors printed out with the form.
356356
a ``required`` attribute on fields that are required. For browsers that
357357
support HTML5, this will result in a native browser message being displayed
358358
if the user tries to submit the form with that field blank.
359-
359+
360360
Generated forms take full advantage of this new feature by adding sensible
361361
HTML attributes that trigger the validation. The client-side validation,
362362
however, can be disabled by adding the ``novalidate`` attribute to the
@@ -484,13 +484,13 @@ the documentation for each type.
484484
that HTML5-ready browsers will apply client-side validation if the field
485485
is left blank. If you don't want this behavior, either set the ``required``
486486
option on your field to ``false`` or :ref:`disable HTML5 validation<book-forms-html5-validation-disable>`.
487-
487+
488488
Also note that setting the ``required`` option to ``true`` will **not**
489489
result in server-side validation to be applied. In other words, if a
490490
user submits a blank value for the field (either with an old browser
491491
or web service, for example), it will be accepted as a valid value unless
492492
you use Symfony's ``NotBlank`` or ``NotNull`` validation constraint.
493-
493+
494494
In other words, the ``required`` option is "nice", but true server-side
495495
validation should *always* be used.
496496

@@ -569,7 +569,7 @@ the correct values of a number of field options.
569569
option can be guessed from the validation constrains (if ``MinLength``
570570
or ``Min`` is used) or from the Doctrine metadata (via the field's length).
571571

572-
* ``max_length``: Similar to ``min_length``, the maximum length can also
572+
* ``max_length``: Similar to ``min_length``, the maximum length can also
573573
be guessed.
574574

575575
.. note::
@@ -651,11 +651,11 @@ output can be customized on many different levels.
651651
.. tip::
652652

653653
You can access the current data of your form via ``form.vars.value``:
654-
654+
655655
.. configuration-block::
656656

657657
.. code-block:: jinja
658-
658+
659659
{{ form.vars.value.task }}
660660
661661
.. code-block:: html+php
@@ -857,15 +857,15 @@ the choice is ultimately up to you.
857857
}
858858

859859
.. tip::
860-
861-
When mapping forms to objects, all fields are mapped. Any fields on the
860+
861+
When mapping forms to objects, all fields are mapped. Any fields on the
862862
form that do not exist on the mapped object will cause an exception to
863863
be thrown.
864-
864+
865865
In cases where you need extra fields in the form (for example: a "do you
866866
agree with these terms" checkbox) that will not be mapped to the underlying
867867
object, you need to set the property_path option to ``false``::
868-
868+
869869
public function buildForm(FormBuilder $builder, array $options)
870870
{
871871
$builder->add('task');
@@ -1122,6 +1122,8 @@ renders the form:
11221122

11231123
{% form_theme form 'AcmeTaskBundle:Form:fields.html.twig' %}
11241124

1125+
{% form_theme form 'AcmeTaskBundle:Form:fields.html.twig' 'AcmeTaskBundle:Form:fields2.html.twig' %}
1126+
11251127
<form ...>
11261128

11271129
.. code-block:: html+php
@@ -1130,6 +1132,8 @@ renders the form:
11301132

11311133
<?php $view['form']->setTheme($form, array('AcmeTaskBundle:Form')) ?>
11321134

1135+
<?php $view['form']->setTheme($form, array('AcmeTaskBundle:Form', 'AcmeTaskBundle:Form')) ?>
1136+
11331137
<form ...>
11341138

11351139
The ``form_theme`` tag (in Twig) "imports" the fragments defined in the given
@@ -1138,6 +1142,13 @@ template and uses them when rendering the form. In other words, when the
11381142
block from your custom theme (instead of the default ``field_row`` block
11391143
that ships with Symfony).
11401144

1145+
Your custom theme does not have to override all the blocks. When rendering a block
1146+
which is not overridden in your custom theme, the theming engine will fall back
1147+
to the global theme (defined at the bundle level).
1148+
1149+
If several custom themes are provided they will be searched in the listed order
1150+
before falling back to the global theme.
1151+
11411152
To customize any portion of a form, you just need to override the appropriate
11421153
fragment. Knowing exactly which block or file to override is the subject of
11431154
the next section.
@@ -1385,7 +1396,7 @@ The CSRF token can be customized on a form-by-form basis. For example::
13851396
class TaskType extends AbstractType
13861397
{
13871398
// ...
1388-
1399+
13891400
public function getDefaultOptions(array $options)
13901401
{
13911402
return array(
@@ -1396,7 +1407,7 @@ The CSRF token can be customized on a form-by-form basis. For example::
13961407
'intention' => 'task_item',
13971408
);
13981409
}
1399-
1410+
14001411
// ...
14011412
}
14021413

@@ -1435,14 +1446,14 @@ an array of the submitted data. This is actually really easy::
14351446
->add('email', 'email')
14361447
->add('message', 'textarea')
14371448
->getForm();
1438-
1449+
14391450
if ($request->getMethod() == 'POST') {
14401451
$form->bindRequest($request);
14411452

14421453
// data is an array with "name", "email", and "message" keys
14431454
$data = $form->getData();
14441455
}
1445-
1456+
14461457
// ... render the form
14471458
}
14481459

@@ -1462,14 +1473,14 @@ an array.
14621473

14631474
.. tip::
14641475

1465-
You can also access POST values (in this case "name") directly through
1476+
You can also access POST values (in this case "name") directly through
14661477
the request object, like so:
14671478

14681479
.. code-block:: php
14691480
14701481
$this->get('request')->request->get('name');
14711482
1472-
Be advised, however, that in most cases using the getData() method is
1483+
Be advised, however, that in most cases using the getData() method is
14731484
a better choice, since it returns the data (usually an object) after
14741485
it's been transformed by the form framework.
14751486

@@ -1524,15 +1535,15 @@ method to specify the option::
15241535
'name' => new MinLength(5),
15251536
'email' => new Email(array('message' => 'Invalid email address')),
15261537
));
1527-
1538+
15281539
return array('validation_constraint' => $collectionConstraint);
15291540
}
15301541
}
15311542

15321543
Now, you have the flexibility to create forms - with validation - that return
15331544
an array of data, instead of an object. In most cases, it's better - and
15341545
certainly more robust - to bind your form to an object. But for simple forms,
1535-
this is a great approach.
1546+
this is a great approach.
15361547

15371548
Final Thoughts
15381549
--------------

0 commit comments

Comments
 (0)
0