-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Comply with best practices, Round 2 #4507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3c71b6d
c8ce507
de4fcf4
4ef1ef3
a29f9fb
2a97453
fdc460d
5ee9791
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,14 +144,16 @@ helper functions: | |
.. code-block:: html+jinja | ||
|
||
{# app/Resources/views/Default/new.html.twig #} | ||
|
||
{{ form(form) }} | ||
{{ form_start(form) }} | ||
{{ form_widget(form) }} | ||
{{ form_end(form) }} | ||
|
||
.. code-block:: html+php | ||
|
||
<!-- app/Resources/views/Default/new.html.php --> | ||
|
||
<?php echo $view['form']->form($form) ?> | ||
<?php echo $view['form']->start($form) ?> | ||
<?php echo $view['form']->widget($form) ?> | ||
<?php echo $view['form']->end($form) ?> | ||
|
||
.. image:: /images/book/form-simple.png | ||
:align: center | ||
|
@@ -162,12 +164,24 @@ helper functions: | |
the same URL that it was displayed in. You will learn later how to | ||
change the request method and the target URL of the form. | ||
|
||
That's it! By printing ``form(form)``, each field in the form is rendered, along | ||
with a label and error message (if there is one). The ``form`` function also | ||
surrounds everything in the necessary HTML ``<form>`` tag. As easy as this is, | ||
it's not very flexible (yet). Usually, you'll want to render each form field | ||
individually so you can control how the form looks. You'll learn how to do | ||
that in the ":ref:`form-rendering-template`" section. | ||
That's it! Just three lines are needed to render the complete form: | ||
|
||
* ``form_start(form)`` - Renders the start tag of the form, including the | ||
correct enctype attributes when using file uploads; | ||
|
||
* ``form_widget(form)`` - Renders all fields, along with a label and error | ||
message (if there is one) input element; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sentence doesn't quite make sense. Maybe something like:
|
||
|
||
* ``form_end()`` - Renders the end tag of the form and any fields that have not | ||
yet been rendered, in case you rendered each field yourself. This is useful | ||
for rendering hidden fields and taking advantage of the automatic | ||
:ref:`CSRF Protection <forms-csrf>`. | ||
|
||
.. seealso:: | ||
|
||
As easy as this is, it's not very flexible (yet). Usually, you'll want to | ||
render each form field individually so you can control how the form looks. | ||
You'll learn how to do that in the ":ref:`form-rendering-template`" section. | ||
|
||
Before moving on, notice how the rendered ``task`` input field has the value | ||
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: | |
<?php echo $view['form']->row($form['dueDate']) ?> | ||
<?php echo $view['form']->end($form) ?> | ||
|
||
Take a look at each part: | ||
|
||
* ``form_start(form)`` - Renders the start tag of the form. | ||
You already know the ``form_start()`` and ``form_end()`` functions, but what do | ||
the other functions do? | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why removing this ? form_row indeed renders the errors of the specific field too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I misread the code example, added it back now |
||
* ``form_errors(form)`` - Renders any errors global to the whole form | ||
(field-specific errors are displayed next to each field); | ||
|
||
* ``form_row(form.dueDate)`` - Renders the label, any errors, and the HTML | ||
form widget for the given field (e.g. ``dueDate``) inside, by default, a | ||
``div`` element; | ||
|
||
* ``form_end()`` - Renders the end tag of the form and any fields that have not | ||
yet been rendered. This is useful for rendering hidden fields and taking | ||
advantage of the automatic :ref:`CSRF Protection <forms-csrf>`. | ||
``div`` element. | ||
|
||
The majority of the work is done by the ``form_row`` helper, which renders | ||
the label, errors and HTML form widget of each field inside a ``div`` tag | ||
by default. In the :ref:`form-theming` section, you'll learn how the ``form_row`` | ||
output can be customized on many different levels. | ||
the label and HTML form widget of each field inside a ``div`` tag by default. | ||
In the :ref:`form-theming` section, you'll learn how the ``form_row`` output | ||
can be customized on many different levels. | ||
|
||
.. tip:: | ||
|
||
|
@@ -958,18 +967,11 @@ to the ``form()`` or the ``form_start()`` helper: | |
.. code-block:: html+jinja | ||
|
||
{# app/Resources/views/Default/new.html.twig #} | ||
{{ form(form, {'action': path('target_route'), 'method': 'GET'}) }} | ||
|
||
{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }} | ||
|
||
.. code-block:: html+php | ||
|
||
<!-- app/Resources/views/Default/newAction.html.php --> | ||
<?php echo $view['form']->form($form, array( | ||
'action' => $view['router']->generate('target_route'), | ||
'method' => 'GET', | ||
)) ?> | ||
|
||
<?php echo $view['form']->start($form, array( | ||
'action' => $view['router']->generate('target_route'), | ||
'method' => 'GET', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attribute I think should be singular