@@ -144,14 +144,16 @@ helper functions:
144
144
.. code-block :: html+jinja
145
145
146
146
{# app/Resources/views/Default/new.html.twig #}
147
-
148
- {{ form(form) }}
147
+ {{ form_start(form) }}
148
+ {{ form_widget(form) }}
149
+ {{ form_end(form) }}
149
150
150
151
.. code-block :: html+php
151
152
152
153
<!-- app/Resources/views/Default/new.html.php -->
153
-
154
- <?php echo $view['form']->form($form) ?>
154
+ <?php echo $view['form']->start($form) ?>
155
+ <?php echo $view['form']->widget($form) ?>
156
+ <?php echo $view['form']->end($form) ?>
155
157
156
158
.. image :: /images/book/form-simple.png
157
159
:align: center
@@ -162,12 +164,24 @@ helper functions:
162
164
the same URL that it was displayed in. You will learn later how to
163
165
change the request method and the target URL of the form.
164
166
165
- That's it! By printing ``form(form) ``, each field in the form is rendered, along
166
- with a label and error message (if there is one). The ``form `` function also
167
- surrounds everything in the necessary HTML ``<form> `` tag. As easy as this is,
168
- it's not very flexible (yet). Usually, you'll want to render each form field
169
- individually so you can control how the form looks. You'll learn how to do
170
- that in the ":ref: `form-rendering-template `" section.
167
+ That's it! Just three lines are needed to render the complete form:
168
+
169
+ * ``form_start(form) `` - Renders the start tag of the form, including the
170
+ correct enctype attributes when using file uploads;
171
+
172
+ * ``form_widget(form) `` - Renders all fields, along with a label and error
173
+ message (if there is one) input element;
174
+
175
+ * ``form_end() `` - Renders the end tag of the form and any fields that have not
176
+ yet been rendered, in case you rendered each field yourself. This is useful
177
+ for rendering hidden fields and taking advantage of the automatic
178
+ :ref: `CSRF Protection <forms-csrf >`.
179
+
180
+ .. seealso ::
181
+
182
+ As easy as this is, it's not very flexible (yet). Usually, you'll want to
183
+ render each form field individually so you can control how the form looks.
184
+ You'll learn how to do that in the ":ref: `form-rendering-template `" section.
171
185
172
186
Before moving on, notice how the rendered ``task `` input field has the value
173
187
of the ``task `` property from the ``$task `` object (i.e. "Write a blog post").
@@ -753,25 +767,20 @@ of code. Of course, you'll usually need much more flexibility when rendering:
753
767
<?php echo $view['form']->row($form['dueDate']) ?>
754
768
<?php echo $view['form']->end($form) ?>
755
769
756
- Take a look at each part:
757
-
758
- * ``form_start(form) `` - Renders the start tag of the form.
770
+ You already know the ``form_start() `` and ``form_end() `` functions, but what do
771
+ the other functions do?
759
772
760
773
* ``form_errors(form) `` - Renders any errors global to the whole form
761
774
(field-specific errors are displayed next to each field);
762
775
763
776
* ``form_row(form.dueDate) `` - Renders the label, any errors, and the HTML
764
777
form widget for the given field (e.g. ``dueDate ``) inside, by default, a
765
- ``div `` element;
766
-
767
- * ``form_end() `` - Renders the end tag of the form and any fields that have not
768
- yet been rendered. This is useful for rendering hidden fields and taking
769
- advantage of the automatic :ref: `CSRF Protection <forms-csrf >`.
778
+ ``div `` element.
770
779
771
780
The majority of the work is done by the ``form_row `` helper, which renders
772
- the label, errors and HTML form widget of each field inside a ``div `` tag
773
- by default. In the :ref: `form-theming ` section, you'll learn how the ``form_row ``
774
- output can be customized on many different levels.
781
+ the label and HTML form widget of each field inside a ``div `` tag by default.
782
+ In the :ref: `form-theming ` section, you'll learn how the ``form_row `` output
783
+ can be customized on many different levels.
775
784
776
785
.. tip ::
777
786
@@ -958,18 +967,11 @@ to the ``form()`` or the ``form_start()`` helper:
958
967
.. code-block :: html+jinja
959
968
960
969
{# app/Resources/views/Default/new.html.twig #}
961
- {{ form(form, {'action': path('target_route'), 'method': 'GET'}) }}
962
-
963
970
{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
964
971
965
972
.. code-block :: html+php
966
973
967
974
<!-- app/Resources/views/Default/newAction.html.php -->
968
- <?php echo $view['form']->form($form, array(
969
- 'action' => $view['router']->generate('target_route'),
970
- 'method' => 'GET',
971
- )) ?>
972
-
973
975
<?php echo $view['form']->start($form, array(
974
976
'action' => $view['router']->generate('target_route'),
975
977
'method' => 'GET',
0 commit comments