Skip to content

Commit 422e0f1

Browse files
committed
feature symfony#4465 Modifying the best practice to use form_start() instead of <form (weaverryan, WouterJ)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes symfony#4465). Discussion ---------- Modifying the best practice to use form_start() instead of <form | Q | A | --- | --- | Doc fix? | no | New docs? | no | Applies to | 2.3+ | Fixed tickets | symfony#4402 Hi guys! See symfony#4402. This proposes recommending to use `form_start` for the reasons there. There are pros and cons, but after nice chat, I think the pros outweigh the cons. /cc @webmozart Thanks! Commits ------- ae3b3cd Fixed typo f1708f5 Modifying the best practice to use form_start() instead of <form
2 parents 0a21446 + ae3b3cd commit 422e0f1

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

best_practices/forms.rst

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,29 +157,15 @@ There are a lot of ways to render your form, ranging from rendering the entire
157157
thing in one line to rendering each part of each field independently. The
158158
best way depends on how much customization you need.
159159

160-
The simplest way - which is especially useful during development - is to render
161-
the form tags manually and then use ``form_widget()`` to render all of the fields:
160+
One of the simplest ways - which is especially useful during development -
161+
is to render the form tags and use ``form_widget()`` to render all of the
162+
fields:
162163

163164
.. code-block:: html+jinja
164165

165-
<form method="POST" {{ form_enctype(form) }}>
166+
{{ form_start(form, {'attr': {'class': 'my-form-class'} }) }}
166167
{{ form_widget(form) }}
167-
</form>
168-
169-
.. best-practice::
170-
171-
Don't use the ``form()`` or ``form_start()`` functions to render the
172-
starting and ending form tags.
173-
174-
Experienced Symfony developers will recognize that we're rendering the ``<form>``
175-
tags manually instead of using the ``form_start()`` or ``form()`` functions.
176-
While those are convenient, they take away from some clarity with little
177-
benefit.
178-
179-
.. tip::
180-
181-
The exception is a delete form because it's really just one button and
182-
so benefits from some of these extra shortcuts.
168+
{{ form_end(form) }}
183169

184170
If you need more control over how your fields are rendered, then you should
185171
remove the ``form_widget(form)`` function and render your fields individually.

0 commit comments

Comments
 (0)