10000 minor #7754 Adding a tip for validation in forms without class (stocc… · symfony/symfony-docs@0b9c93a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b9c93a

Browse files
committed
minor #7754 Adding a tip for validation in forms without class (stoccc, javiereguiluz)
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #7754). Discussion ---------- Adding a tip for validation in forms without class When a form is mapped to an array instead of an object (i.e. a search form), every object in the array is validated with Symfony\Component\Validator\Constraints\Valid constraint. For example a search form mapped to an array including a field of type Symfony\Bridge\Doctrine\Form\Type\EntityType will validate the choosen entity itself, resulting in an invalid form if the (already persisted) entity is, for some reasons, invalid. References: https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php#L171:L186 I'm wondering if this behavior is a bug, while the validation of objects has this approach "If an object is passed without explicit constraints, validate that object against the constraints defined for the object's class [eventually none]" https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php#L154:L169 Commits ------- eb26f28 Minor reword 3177c1d Adding a tip for validation in forms without class
2 parents c6a5a08 + eb26f28 commit 0b9c93a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

form/without_class.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,9 @@ but here's a short example:
105105
.. code-block:: php
106106
107107
new NotBlank(array('groups' => array('create', 'update')));
108+
109+
.. tip::
110+
111+
If the form is not mapped to an object, every object in your array of
112+
submitted data is validated using the ``Symfony\Component\Validator\Constraints\Valid``
113+
constraint, unless you :doc:`disable validation </form/disabling_validation>`.

0 commit comments

Comments
 (0)
0