@@ -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
@@ -447,13 +447,13 @@ the documentation for each type.
447
447
that HTML5-ready browsers will apply client-side validation if the field
448
448
is left blank. If you don't want this behavior, either set the ``required ``
449
449
option on your field to ``false `` or :ref: `disable HTML5 validation<book-forms-html5-validation-disable> `.
450
-
450
+
451
451
Also note that setting the ``required `` option to ``true `` will **not **
452
452
result in server-side validation to be applied. In other words, if a
453
453
user submits a blank value for the field (either with an old browser
454
454
or web service, for example), it will be accepted as a valid value unless
455
455
you use Symfony's ``NotBlank `` or ``NotNull `` validation constraint.
456
-
456
+
457
457
In other words, the ``required `` option is "nice", but true server-side
458
458
validation should *always * be used.
459
459
@@ -532,7 +532,7 @@ the correct values of a number of field options.
532
532
option can be guessed from the validation constrains (if ``MinLength ``
533
533
or ``Min `` is used) or from the Doctrine metadata (via the field's length).
534
534
535
- * ``max_length ``: Similar to ``min_length ``, the maximum length can also
535
+ * ``max_length ``: Similar to ``min_length ``, the maximum length can also
536
536
be guessed.
537
537
538
538
.. note ::
@@ -614,11 +614,11 @@ output can be customized on many different levels.
614
614
.. tip ::
615
615
616
616
You can access the current data of your form via ``form.vars.value ``:
617
-
617
+
618
618
.. configuration-block ::
619
619
620
620
.. code-block :: jinja
621
-
621
+
622
622
{{ form.vars.value.task }}
623
623
624
624
.. code-block :: html+php
@@ -820,15 +820,15 @@ the choice is ultimately up to you.
820
820
}
821
821
822
822
.. tip ::
823
-
824
- When mapping forms to objects, all fields are mapped. Any fields on the
823
+
824
+ When mapping forms to objects, all fields are mapped. Any fields on the
825
825
form that do not exist on the mapped object will cause an exception to
826
826
be thrown.
827
-
827
+
828
828
In cases where you need extra fields in the form (for example: a "do you
829
829
agree with these terms" checkbox) that will not be mapped to the underlying
830
830
object, you need to set the property_path option to ``false ``::
831
-
831
+
832
832
public function buildForm(FormBuilder $builder, array $options)
833
833
{
834
834
$builder->add('task');
@@ -1085,6 +1085,8 @@ renders the form:
1085
1085
1086
1086
{% form_theme form 'AcmeTaskBundle:Form: fields.html.twig' %}
1087
1087
1088
+ {% form_theme form 'AcmeTaskBundle:Form: fields.html.twig' 'AcmeTaskBundle:Form: fields2.html.twig' %}
1089
+
1088
1090
<form ...>
1089
1091
1090
1092
.. code-block :: html+php
@@ -1093,6 +1095,8 @@ renders the form:
1093
1095
1094
1096
<?php $view['form']->setTheme($form, array('AcmeTaskBundle:Form')) ?>
1095
1097
1098
+ <?php $view['form']->setTheme($form, array('AcmeTaskBundle:Form', 'AcmeTaskBundle:Form')) ?>
1099
+
1096
1100
<form ...>
1097
1101
1098
1102
The ``form_theme `` tag (in Twig) "imports" the fragments defined in the given
@@ -1101,6 +1105,13 @@ template and uses them when rendering the form. In other words, when the
1101
1105
block from your custom theme (instead of the default ``field_row `` block
1102
1106
that ships with Symfony).
1103
1107
1108
+ Your custom theme does not have to override all the blocks. When rendering a block
1109
+ which is not overridden in your custom theme, the theming engine will fall back
1110
+ to the global theme (defined at the bundle level).
1111
+
1112
+ If several custom themes are provided they will be searched in the listed order
1113
+ before falling back to the global theme.
1114
+
1104
1115
To customize any portion of a form, you just need to override the appropriate
1105
1116
fragment. Knowing exactly which block or file to override is the subject of
1106
1117
the next section.
@@ -1348,7 +1359,7 @@ The CSRF token can be customized on a form-by-form basis. For example::
1348
1359
class TaskType extends AbstractType
1349
1360
{
1350
1361
// ...
1351
-
1362
+
1352
1363
public function getDefaultOptions(array $options)
1353
1364
{
1354
1365
return array(
@@ -1359,7 +1370,7 @@ The CSRF token can be customized on a form-by-form basis. For example::
1359
1370
'intention' => 'task_item',
1360
1371
);
1361
1372
}
1362
-
1373
+
1363
1374
// ...
1364
1375
}
1365
1376
@@ -1398,14 +1409,14 @@ an array of the submitted data. This is actually really easy::
1398
1409
->add('email', 'email')
1399
1410
->add('message', 'textarea')
1400
1411
->getForm();
1401
-
1412
+
1402
1413
if ($request->getMethod() == 'POST') {
1403
1414
$form->bindRequest($request);
1404
1415
1405
1416
// data is an array with "name", "email", and "message" keys
1406
1417
$data = $form->getData();
1407
1418
}
1408
-
1419
+
1409
1420
// ... render the form
1410
1421
}
1411
1422
@@ -1425,14 +1436,14 @@ an array.
1425
1436
1426
1437
.. tip ::
1427
1438
1428
- You can also access POST values (in this case "name") directly through
1439
+ You can also access POST values (in this case "name") directly through
1429
1440
the request object, like so:
1430
1441
1431
1442
.. code-block :: php
1432
1443
1433
1444
$this->get('request')->request->get('name');
1434
1445
1435
- Be advised, however, that in most cases using the getData() method is
1446
+ Be advised, however, that in most cases using the getData() method is
1436
1447
a better choice, since it returns the data (usually an object) after
1437
1448
it's been transformed by the form framework.
1438
1449
@@ -1487,15 +1498,15 @@ method to specify the option::
1487
1498
'name' => new MinLength(5),
1488
1499
'email' => new Email(array('message' => 'Invalid email address')),
1489
1500
));
1490
-
1501
+
1491
1502
return array('validation_constraint' => $collectionConstraint);
1492
1503
}
1493
1504
}
1494
1505
1495
1506
Now, you have the flexibility to create forms - with validation - that return
1496
1507
an array of data, instead of an object. In most cases, it's better - and
1497
1508
certainly more robust - to bind your form to an object. But for simple forms,
1498
- this is a great approach.
1509
+ this is a great approach.
1499
1510
1500
1511
Final Thoughts
1501
1512
--------------
0 commit comments