8000 [Form] Forward Form::submit(Request) to Form::HandleRequest by 0mars · Pull Request #16088 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Forward Form::submit(Request) to Form::HandleRequest #16088

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 4 commits into from

Conversation

0mars
Copy link
@0mars 0mars commented Oct 2, 2015

When the argument of Form::submit is a Request object it forwards to Form::HandleRequest.
Fixes the issue with uploaded files exceeding post_max_size,
and form marked as valid with empty fields.

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #13291
License MIT
Doc PR

…eRequest

When the argument of Form::submit is a Request object it forwards to
Form::HandleRequest.
Fixes the issue with uploaded files exceeding post_max_size,
and form marked valid with empty fields.
@Tobion
Copy link
Contributor
Tobion commented Oct 2, 2015

submit() does not work with Request only bind() allows to pass a Request and this is deprecated anyway. See 41b0127#diff-0901ceb76939b17cd920bc69aa52d21fR38 Nvm, apparently submit should also support this until 3.0 according to the deprecations, probably to ease the upgrade path so people can just rename bind to submit.

@Tobion
Copy link
Contributor
Tobion commented Oct 2, 2015

I think the actual problem is that #11924 fixed the request handlers, but did not fix the legacy appraoch using the https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php
But maybe the proposed solution here is really the easiest fix.

@@ -507,6 +508,10 @@ public function handleRequest($request = null)
*/
public function submit($submittedData, $clearMissing = true)
{
if ($submittedData instanceof Request) {
return $this->handleRequest($submittedData);
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be moved after the throw new AlreadySubmittedException

Copy link
Contributor

Choose a reason for hiding this comment

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

also you need to skip the following code in this case because the request handler itself also calls submit. see https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php#L116
so otherwise the form would be submitted twice and an AlreadySubmittedException is thrown.
have you actually tried to use the fix for your issue? it cannot work in its current form AFAIK.

Copy link
Author

Choose a reason for hiding this comment

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

It shouldn't throw the AlreadySubmittedException, because it follows a different execution path inside submit()

1 Form::submit(Request)
1.1 Form::handleRequest(Request)
1.1.1 HttpFoundationRequestHandler::handleRequest(Form, Request)
1.1.1.1 Form::submit(data)

only at: 1.1.1.1 Form::submitted = true

And if we used bind
preBindEvent dispatches (does not submit, so submitted is still false)
bind will call Form::submit(Request) which will follow the same execution path above.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah there is a return in front of handleRequest. I didn't see that and this is what I thought is missing.

0mars added a commit to 0mars/symfony that referenced this pull request Oct 3, 2015
@fabpot fabpot added the Form label Oct 5, 2015
@fabpot fabpot changed the title Bug #13291 [Form] Forward Form::submit(Request) to Form::HandleRequest [Form] Forward Form::submit(Request) to Form::HandleRequest Oct 6, 2015
@fabpot
Copy link
Member
fabpot commented Oct 6, 2015

@Tobion Does it get a +1 from you?

@Tobion
Copy link
Contributor
Tobion commented Oct 6, 2015

Hm I see one problem. When using submit the form is always submitted. But now that it uses handleRequest instead, the form might not be submitted anymore because the form only gets submitted when the request method is the same as the form config (which defaults to POST). So GET requests with a form might not be submitted anymore which is would be a behavior change.

So I think the only non-breaking solution is to fix the https://github.com/symfony/symfony/blob/2.3/src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php according to https://github.com/symfony/symfony/blob/2.3/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php.

@Tobion
Copy link
Contributor
Tobion commented Oct 6, 2015

But then again, this approach is deprecated anyway. So I'm not sure it's really worth to do it.
I'm closing this PR with the current solution due to above reasons.
@0mars If you have the time feel free to create a new PR with the fixed BindRequestListener.

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.

4 participants
0