@@ -356,7 +356,7 @@ corresponding errors printed out with the form.
356
356
a ``required `` attribute on fields that are required. For browsers that
357
357
support HTML5, this will result in a native browser message being displayed
358
358
if the user tries to submit the form with that field blank.
359
-
359
+
360
360
Generated forms take full advantage of this new feature by adding sensible
361
361
HTML attributes that trigger the validation. The client-side validation,
362
362
however, can be disabled by adding the ``novalidate `` attribute to the
@@ -484,13 +484,13 @@ the documentation for each type.
484
484
that HTML5-ready browsers will apply client-side validation if the field
485
485
is left blank. If you don't want this behavior, either set the ``required ``
486
486
option on your field to ``false `` or :ref: `disable HTML5 validation<book-forms-html5-validation-disable> `.
487
-
487
+
488
488
Also note that setting the ``required `` option to ``true `` will **not **
489
489
result in server-side validation to be applied. In other words, if a
490
490
user submits a blank value for the field (either with an old browser
491
491
or web service, for example), it will be accepted as a valid value unless
492
492
you use Symfony's ``NotBlank `` or ``NotNull `` validation constraint.
493
-
493
+
494
494
In other words, the ``required `` option is "nice", but true server-side
495
495
validation should *always * be used.
496
496
@@ -569,7 +569,7 @@ the correct values of a number of field options.
569
569
option can be guessed from the validation constrains (if ``MinLength ``
570
570
or ``Min `` is used) or from the Doctrine metadata (via the field's length).
571
571
572
- * ``max_length ``: Similar to ``min_length ``, the maximum length can also
572
+ * ``max_length ``: Similar to ``min_length ``, the maximum length can also
573
573
be guessed.
574
574
575
575
.. note ::
@@ -651,11 +651,11 @@ output can be customized on many different levels.
651
651
.. tip ::
652
652
653
653
You can access the current data of your form via ``form.vars.value ``:
654
-
654
+
655
655
.. configuration-block ::
656
656
657
657
.. code-block :: jinja
658
-
658
+
659
659
{{ form.vars.value.task }}
660
660
661
661
.. code-block :: html+php
@@ -857,15 +857,15 @@ the choice is ultimately up to you.
857
857
}
858
858
859
859
.. 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
862
862
form that do not exist on the mapped object will cause an exception to
863
863
be thrown.
864
-
864
+
865
865
In cases where you need extra fields in the form (for example: a "do you
866
866
agree with these terms" checkbox) that will not be mapped to the underlying
867
867
object, you need to set the property_path option to ``false ``::
868
-
868
+
869
869
public function buildForm(FormBuilder $builder, array $options)
870
870
{
871
871
$builder->add('task');
@@ -1122,6 +1122,8 @@ renders the form:
1122
1122
1123
1123
{% form_theme form 'AcmeTaskBundle:Form: fields.html.twig' %}
1124
1124
1125
+ {% form_theme form 'AcmeTaskBundle:Form: fields.html.twig' 'AcmeTaskBundle:Form: fields2.html.twig' %}
1126
+
1125
1127
<form ...>
1126
1128
1127
1129
.. code-block :: html+php
@@ -1130,6 +1132,8 @@ renders the form:
1130
1132
1131
1133
<?php $view['form']->setTheme($form, array('AcmeTaskBundle:Form')) ?>
1132
1134
1135
+ <?php $view['form']->setTheme($form, array('AcmeTaskBundle:Form', 'AcmeTaskBundle:Form')) ?>
1136
+
1133
1137
<form ...>
1134
1138
1135
1139
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
1138
1142
block from your custom theme (instead of the default ``field_row `` block
1139
1143
that ships with Symfony).
1140
1144
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
+
1141
1152
To customize any portion of a form, you just need to override the appropriate
1142
1153
fragment. Knowing exactly which block or file to override is the subject of
1143
1154
the next section.
@@ -1385,7 +1396,7 @@ The CSRF token can be customized on a form-by-form basis. For example::
1385
1396
class TaskType extends AbstractType
1386
1397
{
1387
1398
// ...
1388
-
1399
+
1389
1400
public function getDefaultOptions(array $options)
1390
1401
{
1391
1402
return array(
@@ -1396,7 +1407,7 @@ The CSRF token can be customized on a form-by-form basis. For example::
1396
1407
'intention' => 'task_item',
1397
1408
);
1398
1409
}
1399
-
1410
+
1400
1411
// ...
1401
1412
}
1402
1413
@@ -1435,14 +1446,14 @@ an array of the submitted data. This is actually really easy::
1435
1446
->add('email', 'email')
1436
1447
->add('message', 'textarea')
1437
1448
->getForm();
1438
-
1449
+
1439
1450
if ($request->getMethod() == 'POST') {
1440
1451
$form->bindRequest($request);
1441
1452
1442
1453
// data is an array with "name", "email", and "message" keys
1443
1454
$data = $form->getData();
1444
1455
}
1445
-
1456
+
1446
1457
// ... render the form
1447
1458
}
1448
1459
@@ -1462,14 +1473,14 @@ an array.
1462
1473
1463
1474
.. tip ::
1464
1475
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
1466
1477
the request object, like so:
1467
1478
1468
1479
.. code-block :: php
1469
1480
1470
1481
$this->get('request')->request->get('name');
1471
1482
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
1473
1484
a better choice, since it returns the data (usually an object) after
1474
1485
it's been transformed by the form framework.
1475
1486
@@ -1524,15 +1535,15 @@ method to specify the option::
1524
1535
'name' => new MinLength(5),
1525
1536
'email' => new Email(array('message' => 'Invalid email address')),
1526
1537
));
1527
-
1538
+
1528
1539
return array('validation_constraint' => $collectionConstraint);
1529
1540
}
1530
1541
}
1531
1542
1532
1543
Now, you have the flexibility to create forms - with validation - that return
1533
1544
an array of data, instead of an object. In most cases, it's better - and
1534
1545
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.
1536
1547
1537
1548
Final Thoughts
1538
1549
--------------
0 commit comments