Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Form] Fix submitting checkboxes and radios with PATCH method#17771
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
clearMissing falseclearMissing falsesrc/Symfony/Component/Form/Form.php Outdated
| if (method_exists($child,'getClickedButton') &&null !==$child->getClickedButton()) { | ||
| $this->clickedButton =$child->getClickedButton(); | ||
| } | ||
| }elseif (!$isSubmitted && !$clearMissing &&array_key_exists($name,$submittedData)) { |
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.
This never evaluates to TRUE, because $isSubmitted = array_key_exists($name, $submittedData);
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 know, this is a dummy test, seeHeahDude@935b2da#diff-ca5e25b47f3ecc94cd557946aeb486c6R583 for the right fix
clearMissing falseclearMissing falseclearMissing falseclearMissing falseclearMissing falseclearMissing falseclearMissing falseclearMissing falsesrc/Symfony/Component/Form/Form.php Outdated
| foreach ($this->childrenas$name =>$child) { | ||
| $isSubmitted =array_key_exists($name,$submittedData); | ||
| $clearMissing =$this->getConfig()->getOption('expanded') ?:$clearMissing; |
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.
expanded being an option forChoiceType, it looks weird to "hardcode" this condition here.
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.
@fabpot I have the same feeling, but I miss to find another way... expanded choice type seems to be a really singular case.
Feel free to close this PR if there is a better fix.
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.
@fabpot unless I missed something else,$clearMissing in only used as an argument ofFormType::submit() and there is no way no access its behaviour from a type definition, or it would need to override this method.
Handling a custom submit process for a particular form type would require a big refactoring...
@webmozart any thoughts ?
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.
a "no fix" is still a solution, but the doc should mention that using a PATCH method is not handled byChoiceType
clearMissing falseclearMissing falseclearMissing falseclearMissing falseHeahDude commentedFeb 23, 2016
Ok I've updated the fix as it comes from the |
Silverspur commentedFeb 23, 2016
I'm unsure this new fix is acceptable because it leads to the opposite problem (if I'm not mistaken): |
HeahDude commentedFeb 23, 2016
@Silverspur It wouldn't if there is no field for that |
Silverspur commentedFeb 23, 2016
You're perfectly right, I got confused. My bad. |
HeahDude commentedFeb 23, 2016
Maybe I should add the @webmozart, could you confirm ? |
Silverspur commentedFeb 23, 2016
@HeahDude Actually the I still find odd the fact that the data related to a fieldpresent in the form type but with no data sent will :
I know the root of this issues comes from the way HTTP forms are designed, but I still find this discrepancies quite unconsistent, and I think it somehow questions the pertinence of systematically setting $clearMissing to false for PATCH, since the setting will only apply to certain types of fields. |
HeahDude commentedFeb 23, 2016
I don't agree with you as it actually depends on the mandatory
This was the misinterpretation of my first fix, but it's not true as we found out thanks to your issue ;) |
HeahDude commentedFeb 24, 2016
Ok so I may need to clarify the patch I propose here, as I really think this time this is the way to fix it, at least for keeping BC in 2.7. #16802 and#17799 pointed out that the expanded Then thanks to#17899, I understood that for once A PATCH method would fail forany nested So to fix this in a BC way for 2.7, we need IMO this "hack" as the What I suggest from here, is to revert this change in Another option (still BC) for What do you think symfony deciders ? |
HeahDude commentedFeb 25, 2016
Actually this is the same case for the compound ~~~~~~~~ **type**: ``boolean`` **default**: ``false`` This option specifies whether the type contains child types or not. This option is managed internally for built-in types, so there is no need to configure it explicitly. |
fabpot commentedJun 14, 2016
@HeahDude I can see a list of task in the PR description. Are they still accurate? Anything we can do to move this PR forward? Thanks. |
HeahDude commentedJun 15, 2016
fabpot commentedJul 1, 2016
Looks like a bug fix to me, so 2.7 seems fine. |
b1d922a to096ef21CompareclearMissing falseHeahDude commentedDec 3, 2016
Ok this one is finally ready 🎉, had the chance to talk about this with@webmozart in person during the Hack Day in SymfonyCon Berlin, and we agreed on keeping this internal for now. I've just renamed the option |
HeahDude commentedDec 3, 2016
status: needs work |
Simperfit commentedDec 9, 2016
Great work@HeahDude ! |
| $resolver->setNormalizer('force_submit',function (Options$options) { | ||
| // If pre set data is true, we need to ensure that $emptyData will be submitted | ||
| return (bool)$options['data']; | ||
| returnisset($options['data']) &&(bool)$options['data']; |
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.
how about
return !empty($options['data']);
instead?
xabbuh commentedDec 18, 2016
@HeahDude What is the state here? |
HeahDude commentedDec 18, 2016
@xabbuh I'm still quite reluctant to merge this fix as is, as it makes impossible to ignore checkboxes or radios with PATCH request (they will always be submitted). I think I should reduce the scope of this PR to act only on parent forms containing such fields like the I mean actually problems with PATCH method are quite expected and the component should handle only two cases IMHO:
So the problem is really about getting the proper array of submitted data when dealing with HTML form's submission. Wdyt? |
backbone87 commentedFeb 24, 2017
I am against this PR in its current state Like i already stated here and explained in#20210 (comment) the problem is not the the The |
fabpot commentedMar 22, 2017
To be closed? Updated? |
HeahDude commentedMar 26, 2017
Closing for now. |
ostrolucky commentedOct 12, 2019
@HeahDude Any change to continue attempt to fix this? I've taken a look at request handler as suggested in#17771 (comment), but it would require recursive iteration over all form children to find ChoiceType there. It would be quite precedens doing that and I don't think people would be happy to merge something like that |
Uh oh!
There was an error while loading.Please reload this page.
The bug seems to make it impossible to submit an expanded
ChoiceTypewith a PATCH method, see#17799.