Skip to content

Commit 2d5e4af

Browse files
committed
Merge branch '2.8' into 3.4
* 2.8: Change link to actual demo repo Remove unnecessary semicolons Mentioned how to redirect and maintain the query string Use cross references for internal links Added a note on forms validation Mentioned the <optgroup> html tag explicitly
2 parents 5c55bea + 958735c commit 2d5e4af

File tree

9 files changed

+46
-11
lines changed

9 files changed

+46
-11
lines changed

best_practices/forms.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,35 @@ view layer:
146146
class="btn btn-default pull-right" />
147147
{{ form_end(form) }}
148148

149+
Validation
150+
----------
151+
152+
The :ref:`constraints <reference-form-option-constraints>` option allows you to
153+
attach :doc:`validation constraints </reference/constraints>` to any form field.
154+
However, doing that prevents the validation from being reused in other forms or
155+
other places where the mapped object is used.
156+
157+
.. best-practice::
158+
159+
Do not define your validation constraints in the form but on the object the
160+
form is mapped to.
161+
162+
For example, to validate that the title of the post edited with a form is not
163+
blank, add the following in the ``Post`` object::
164+
165+
// src/Entity/Post.php
166+
167+
// ...
168+
use Symfony\Component\Validator\Constraints as Assert;
169+
170+
class Post
171+
{
172+
/**
173+
* @Assert\NotBlank()
174+
*/
175+
public $title;
176+
}
177+
149178
Rendering the Form
150179
------------------
151180

components/process.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ instead::
312312
use Symfony\Component\Process\PhpProcess;
313313

314314
$process = new PhpProcess(<<<EOF
315-
<?= 'Hello World'; ?>
315+
<?= 'Hello World' ?>
316316
EOF
317317
);
318318
$process->run();

controller.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ and ``redirect()`` methods::
183183
// redirects to a route with parameters
184184
return $this->redirectToRoute('blog_show', array('slug' => 'my-page'));
185185

186+
// redirects to a route and mantains the original query string parameters
187+
return $this->redirectToRoute('blog_show', $request->query->all());
188+
186189
// redirects externally
187190
return $this->redirect('http://symfony.com/doc');
188191
}

reference/forms/types/choice.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ text that's shown to the user. But that can be completely customized via the
129129
Grouping Options
130130
----------------
131131

132-
You can easily "group" options in a select by passing a multi-dimensional choices array::
132+
You can group the ``<option>`` elements of a ``<select>`` into ``<optgroup>``
133+
by passing a multi-dimensional ``choices`` array::
133134

134135
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
135136
// ...

reference/forms/types/form.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ option on the form.
6767

6868
.. include:: /reference/forms/types/options/compound.rst.inc
6969

70+
.. _reference-form-option-constraints:
71+
7072
.. include:: /reference/forms/types/options/constraints.rst.inc
7173

7274
.. include:: /reference/forms/types/options/data.rst.inc

reference/forms/types/options/group_by.rst.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ group_by
33

44
**type**: ``array``, ``callable`` or ``string`` **default**: ``null``
55

6-
You can easily "group" options in a select simply by passing a multi-dimensional
7-
array to ``choices``. See the :ref:`Grouping Options <form-choices-simple-grouping>`
8-
section about that.
6+
You can group the ``<option>`` elements of a ``<select>`` into ``<optgroup>``
7+
by passing a multi-dimensional array to ``choices``. See the
8+
:ref:`Grouping Options <form-choices-simple-grouping>` section about that.
99

1010
The ``group_by`` option is an alternative way to group choices, which gives you
1111
a bit more flexibility.
@@ -32,7 +32,7 @@ Take the following example::
3232
));
3333

3434
This groups the dates that are within 3 days into "Soon" and everything else into
35-
a "Later" group:
35+
a "Later" ``<optgroup>``:
3636

3737
.. image:: /_images/reference/form/choice-example5.png
3838
:align: center

security.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ You can also use expressions inside your templates:
955955
'"ROLE_ADMIN" in roles or (not is_anonymous() and user.isSuperAdmin())'
956956
))): ?>
957957
<a href="...">Delete</a>
958-
<?php endif; ?>
958+
<?php endif ?>
959959

960960
For more details on expressions and security, see :doc:`/security/expressions`.
961961

setup.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ Go Deeper with Setup
322322
.. _`Composer`: https://getcomposer.org/
323323
.. _`Phar extension`: https://php.net/manual/en/intro.phar.php
324324
.. _`Symfony Standard Edition`: https://github.com/symfony/symfony-standard
325-
.. _`The Symfony Demo application`: https://github.com/symfony/symfony-demo
325+
.. _`The Symfony Demo application`: https://github.com/symfony/demo
326326
.. _`The Symfony CMF Standard Edition`: https://github.com/symfony-cmf/standard-edition
327327
.. _`Symfony CMF`: http://cmf.symfony.com/
328328
.. _`The Symfony REST Edition`: https://github.com/gimler/symfony-rest-edition

templating/PHP.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ Now that you've created the customized form template, you need to tell Symfony
407407
to use it. Inside the template where you're actually rendering your form,
408408
tell Symfony to use the theme via the ``setTheme()`` helper method::
409409

410-
<?php $view['form']->setTheme($form, array(':form')); ?>
410+
<?php $view['form']->setTheme($form, array(':form')) ?>
411411

412412
<?php $view['form']->widget($form['age']) ?>
413413

@@ -418,7 +418,7 @@ the ``div`` element.
418418
If you want to apply a theme to a specific child form, pass it to the ``setTheme()``
419419
method::
420420

421-
<?php $view['form']->setTheme($form['child'], ':form'); ?>
421+
<?php $view['form']->setTheme($form['child'], ':form') ?>
422422

423423
.. note::
424424

@@ -545,7 +545,7 @@ your template file rather than adding the template as a resource:
545545

546546
.. code-block:: html+php
547547

548-
<?php $view['form']->setTheme($form, array('FrameworkBundle:FormTable')); ?>
548+
<?php $view['form']->setTheme($form, array('FrameworkBundle:FormTable')) ?>
549549

550550
Note that the ``$form`` variable in the above code is the form view variable
551551
that you passed to your template.

0 commit comments

Comments
 (0)