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] add 'force_submit' option to FormType#18053
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
HeahDude commentedMar 8, 2016
| Q | A |
|---|---|
| Branch | master |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #16491 |
| License | MIT |
| Doc PR | symfony/symfony-docs#6353 |
HeahDude commentedMar 8, 2016
It would be better if we could use |
| $this->setRequestData($method,array()); | ||
| $form->expects($this->once()) |
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 think you should add awith() block here.
webmozart commentedMar 8, 2016
Thanks for working on this@HeahDude! :) |
6d9895f toc5034e6CompareHeahDude commentedMar 8, 2016
@webmozart alright, comments addressed! |
c5034e6 to7748f5eComparewebmozart commentedMar 9, 2016
Looks good, thanks@HeahDude! :) 👍 Is anybody taking care of the failed tests? |
HeahDude commentedMar 9, 2016
@webmozart thanks! I think appveyor was fixed by@nicolas-grekas in#18054 and for travis on php 7@xabbuh should have fixed it in#18037. |
xabbuh commentedMar 10, 2016
Yes, failures are unrelated. |
xabbuh commentedMar 10, 2016
Imo this needs to be added to the changelog (to document the new feature) and to the upgrade file as (as people will have to update their own request handler if they built one). |
HeahDude commentedMar 10, 2016
Ok. Status: Needs Work |
7748f5e tod354997Comparerelated tosymfony/symfony#18053Document the new option ‘force_submit’ added to FormType in 3.1It allows request handlers to submit data that does not hold the formname.
d354997 to9ead4acComparerelated tosymfony/symfony#18053Document the new option ‘force_submit’ added to FormType in 3.1It allows request handlers to submit data that does not hold the formname.
HeahDude commentedMar 12, 2016
Status: Needs Review |
UPGRADE-3.1.md Outdated
| in`ResizeFormListener::preSubmit` method has been deprecated and will be | ||
| removed in Symfony 4.0. | ||
| * A new "force_submit" option has been added to allow request handlers to | ||
| submit a form even if its name is not a key of the submitted data array. |
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.
As the new option doesn't force the user to do anything when upgrading it shouldn't be added to the upgrade file.
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.
Fixed, thanks.
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.
Oh sorry, we need to add it to the upgrade file as one needs to change their custom request handlers. Please excuse the confusion.
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 is not mandatory. The option is just available for anyone who wants to use it, but is totally transparent for pure BC.
Final words ?
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.
What do you think@webmozart?
closessymfony#16491.Add a `force_submit` option to FormType with default false,allowing request handlers to submit a form even if its nameis not a key of the submitted data array.
9ead4ac to85bf807Comparerelated tosymfony/symfony#18053Document the new option ‘force_submit’ added to FormType in 3.1It allows request handlers to submit data that does not hold the formname.
webmozart commentedMar 14, 2016
Status: Reviewed 👍 |
javiereguiluz commentedMar 14, 2016
I know I'm very late to this PR ... but I have some concerns about the But this option in fact just removes the form name from the submitted values. Instead of |
HeahDude commentedMar 14, 2016
@javiereguiluz Hopefully one would read the docs before using a new option :) If you think otherwise, do you have a suggestion ? |
webmozart commentedMar 25, 2016
@javiereguiluz That's a very good point, thanks for pointing it out. So in effect what we are controlling is: // When$form->handleRequest($request);// force_submit=true: only submit if $form->getName() present in request$form->submit($request->request->get($form->getName()));// force_submit=true: submit even if $form->getName() not present in request$form->submit($request->request->all()); What about As seen in this snippet, another difference is that - with the option set - we do not submit the data of the form, but the complete request. Does this make sense? Shouldn't we rather submit ping@guilhermeblanco |
webmozart commentedMar 25, 2016
Furthermore, do wereally need this? So far,@guilhermeblanco was the only one who ever needed this feature, and it can easily be fixed by implementing the functionality of the request handler yourself in the controller (or as another |
xabbuh commentedMar 25, 2016
@webmozart Afaics#12528 would (at least partly) be solvable with this change too. |
HeahDude commentedMar 25, 2016
Yes I agree it's more accurate to use What about |
guilhermeblanco commentedMar 27, 2016
@webmozart I think the name There's an alternative, implementing my own RequestHandlerInterface, but still, it takes a couple time to digest what you did wrong when working on a day by day basis and experiencing this issue. |
HeahDude commentedMar 27, 2016
What about adding |
HeahDude commentedMar 27, 2016
I agree it can be useful for API in general and API with GET in particular. |
HeahDude commentedMar 30, 2016
What's the final call on this ? Changing the name is easy to get done for tomorrow :) |
javiereguiluz commentedMar 30, 2016
@HeahDude Bernhard commented the following:
So, if this option is about submitting the request, why not calling it |
HeahDude commentedMar 30, 2016
I agree with all the reasoning here, I would just say I'm not against your proposal, but I don't find it explicit since all form get submitted through request then I go in circle again:
?? |
webmozart commentedMar 31, 2016
I think we're overengineering. This use case can be solved as simply as: $form =$this->createForm(/* ... */);$form->submit($request->query->all());if ($form->isValid()) {// ...} Just replace |
HeahDude commentedMar 31, 2016
I may be wrong but the point of this PR is that we cannot do it if the form name is not the key holding the data to submit, because the request handler will not map it, right ? |
HeahDude commentedMar 31, 2016
@webmozart What do you think about having in 4.0 some clear equivalence: Don't get me wrong, I'm not talking about modifying the way APIs work but about compatibility of dataset and data mapping and the way view data is handled throw the global form lifecycle. |
webmozart commentedApr 1, 2016
The request handler is simply a more user friendly interface to submit(). If you have more elaborate use cases, using submit() directly is simple enough.
What do you mean? What do you see that should be improved? |
HeahDude commentedApr 1, 2016
Thanks for your response :) I mean currently My guess is that it should match the real view value: |
HeahDude commentedApr 2, 2016
On second thought to be able to do that, the data mapping should be done with normalized data, shouldn't it ? |