Skip to content

Commit a58b0d1

Browse files
committed
Merge branch '2.5'
* 2.5: describe how to access form errors Fixed sentence
2 parents 5e7fa55 + fd9c1a0 commit a58b0d1

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

components/console/changing_default_command.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Changing the Default Command
88
The :method:`Symfony\\Component\\Console\\Application::setDefaultCommand`
99
method was introduced in Symfony 2.5.
1010

11-
will always run the ``ListCommand`` when no command name is passed. In order to change
12-
the default command you just need to pass the command name you want to run by
13-
default to the ``setDefaultCommand`` method::
11+
The Console component will always run the ``ListCommand`` when no command name is
12+
passed. In order to change the default command you just need to pass the command
13+
name to the ``setDefaultCommand`` method::
1414

1515
namespace Acme\Console\Command;
1616

components/form/introduction.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,33 @@ and the errors will display next to the fields on error.
660660
For a list of all of the built-in validation constraints, see
661661
:doc:`/reference/constraints`.
662662

663+
Accessing Form Errors
664+
~~~~~~~~~~~~~~~~~~~~~
665+
666+
You can use the :method:`Symfony\\Component\\Form\\FormInterface::getErrors`
667+
method to access the list of errors. Each element is a :class:`Symfony\\Component\\Form\\FormError`
668+
object::
669+
670+
$form = ...;
671+
672+
// ...
673+
674+
// an array of FormError objects, but only errors attached to this form level (e.g. "global errors)
675+
$errors = $form->getErrors();
676+
677+
// an array of FormError objects, but only errors attached to the "firstName" field
678+
$errors = $form['firstName']->getErrors();
679+
680+
// a string representation of all errors of the whole form tree
681+
$errors = $form->getErrorsAsString();
682+
683+
.. note::
684+
685+
If you enable the :ref:`error_bubbling <reference-form-option-error-bubbling>`
686+
option on a field, calling ``getErrors()`` on the parent form will include
687+
errors from that field. However, there is no way to determine which field
688+
an error was originally attached to.
689+
663690
.. _Packagist: https://packagist.org/packages/symfony/form
664691
.. _Twig: http://twig.sensiolabs.org
665692
.. _`Twig Configuration`: http://twig.sensiolabs.org/doc/intro.html

reference/forms/types/form.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ The actual default value of this option depends on other field options:
7878
.. include:: /reference/forms/types/options/empty_data.rst.inc
7979
:start-after: DEFAULT_PLACEHOLDER
8080

81+
.. _reference-form-option-error-bubbling:
82+
8183
.. include:: /reference/forms/types/options/error_bubbling.rst.inc
8284

8385
.. include:: /reference/forms/types/options/error_mapping.rst.inc

0 commit comments

Comments
 (0)