-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added example for direct form submit with validation #11905
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
Conversation
@@ -89,3 +89,8 @@ method, pass the submitted data directly to | |||
"PATCH" method, the validation extension will only handle the submitted | |||
fields. If the underlying data needs to be validated, this should be done | |||
manually, i.e. using the validator. | |||
|
|||
When you need validation for some fields you can extend your data array with the required ones so that they will be validated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually do not understand this addition. This block talks about partial submission of data. Adding more data here seems to defeat the use of a PATCH request as long as I do not miss anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem was that I had a contraints
option in my UpdateUserProfileType
.
This was not thrown an exception without that because of this clearMissing which not throws for not filled fields - as you can read here: symfony/symfony#25331
So then I found out that moving this constraints
option to the entity direct made it work's in the form.
So now instead of having...
->add('email', EmailType::class, ['constraints' => [
new Assert\Email(['groups' => ['profile_update', 'user_registration']]),
]])
I have only this...
->add('email', EmailType::class)
And then my entity got's this.
/**
* @var string
*
* @Assert\Email(groups={"profile_update", "user_registration"})
*/
protected $email;
And then it's working.
But I can not use the constraints
options because it will not validate when the user not PATCH
ing it. Thats the problem.
So my "moving contraints option to entity" solves the problem but not the root cause.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I think we need to expand explanations on the constraints
option instead to make it clear that constraints are ignored if the field they are bound to is not submitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I want to try with this commit with the example 😉
But now you understand what I want/mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #12365
d3db9d5
to
c81d30a
Compare
…trickbussmann) This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #11905). Discussion ---------- Added example for direct form submit with validation See symfony/symfony#25331. I had the same issue. My registration form is filled via an API call and this call contains only filled fields. But when the user is missing all fields its an empty array and then the username and email will not be validated. After I found out that this is the behaviour I want to share this knowledge ;-) Commits ------- c81d30a Added example for direct form submit with validation
Patrick, thanks for this contribution. We finally merged it after a minor reword. |
See symfony/symfony#25331.
I had the same issue.
My registration form is filled via an API call and this call contains only filled fields.
But when the user is missing all fields its an empty array and then the username and email will not be validated.
After I found out that this is the behaviour I want to share this knowledge ;-)