8000 Adding a tip for validation in forms without class by stoccc · Pull Request #7754 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Adding a tip for validation in forms without class #7754

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

Closed
wants to merge 2 commits into from

Conversation

stoccc
Copy link
Contributor
@stoccc stoccc commented Apr 4, 2017

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

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
Copy link
Member
@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks @stoccc

Copy link
Contributor
@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying this!

@xabbuh
Copy link
Member
xabbuh commented Apr 15, 2017

Thank you @stoccc.

xabbuh added a commit that referenced this pull request Apr 15, 2017
…c, 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
@xabbuh xabbuh closed this Apr 15, 2017
@stoccc stoccc deleted the patch-2 branch May 24, 2018 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0