-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
unsubmitted form doesn't get violation mapped #30011
Comments
The Form component is designed to process submitted HTML forms. As far as I can tell, you're not submitting a form, you're posting a JSON object. You can instead use the Symfony Validator to validate the submitted data structure. |
hi, @derrabus , don't get confused by that json data which will be converted to array fed to Symfony form, the same way as FosRestBundle does. |
Can you confirm that the changes proposed in #30265 will fix this issue? |
…requests (xabbuh) This PR was merged into the 3.4 branch. Discussion ---------- [Form] do not validate non-submitted form fields in PATCH requests | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11493, #19788, #20805, #24453, #30011 | License | MIT | Doc PR | When a form field is not embedded as part of a HTTP PATCH requests, its validation constraints configured through the `constraints` option must not be evaluated. The fix from #10567 achieved this by not mapping their violations to the underlying form field. This however also means that constraint violations caused by validating the whole underlying data object will never cause the form to be invalid. This breaks use cases where some constraints may, for example, depend on the value of other properties that were changed by the submitted data. Commits ------- a60d802 do not validate non-submitted form fields in PATCH requests
I am not sure if this is a bug, but the behavior looks strange.
CarBrandType
violation rules
Test
I submitted data without the required field name, I can see a violation happened at
Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener
class, however, calling $form->isValid() will return true, because theSymfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper
doesn't map violation to unsubmitted form. that is the isValid method is not 100% sure the form has no violations. what is the sure way?The text was updated successfully, but these errors were encountered: