Skip to content
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

[Form] Binding a request with a missing file causes an exception instead of an invalid form #6134

Closed
roverwolf opened this issue Nov 27, 2012 · 11 comments

Comments

@roverwolf
Copy link

When a form that requires a file field is bound and the file is missing an exception is raised instead of just having $form->isValid() return false. If the file is not missing then things work well.

Warning: Missing argument 1 for Symfony\Component\HttpFoundation\File\File::__construct(), called in .../Symfony/Component/Form/Extension/Core/Type/FormType.php on line 172

A workaround is to wrap the $form->bind($this->getRequest()) in a try-catch block and then check if $form->isBound().

@Tobion
Copy link
Member

Tobion commented Nov 28, 2012

I confirm this issue.

@andreadelfino
Copy link

This behaviour happened on my application after SF v2.1.3 -> v2.1.4 update, I think due 2fe04e1 changes.
I solved temporally setting data_class to null in form builders, but I don't like this solution... any better idea?

Es:

$builder->add('file', 'file', array('data_class' => null));

@dchaffin
Copy link

@andreadelfino ... I put in the 'data_class' setting you (reluctantly) suggested, but now my NotNull validation is not firing on my file field. It just blows right past it and submits the form. Have you found a better fix for this yet?

Thanks!

@dchaffin
Copy link

@andreadelfino ... Nevermind. I just realized I had commented out my NotNull constraint while testing.

@Tobion
Copy link
Member

Tobion commented Dec 10, 2012

@bschussek can you please have a look. this makes upload forms kinda useless.
The exception is also thrown, if the uploaded file is too big. Normally an error should be assigned to the field.

@ghost
Copy link

ghost commented Dec 13, 2012

Since this update, I've got a 500 error instead of validation failure when I try to post a form without a required file.

@webmozart
Copy link
Contributor

Confirmed.

@diphda
Copy link

diphda commented Dec 13, 2012

I have the same issue, with the last version. It will be fixed?

@webmozart
Copy link
Contributor

Fixed in the referenced PR.

@diphda
Copy link

diphda commented Dec 13, 2012

Thanks!
On Thu, 13 Dec 2012 05:35:49 -0800
Bernhard Schussek notifications@github.com wrote:

Fixed in the referenced PR.


Reply to this email directly or view it on GitHub:
#6134 (comment)

fabpot added a commit that referenced this issue Dec 13, 2012
This PR was merged into the 2.1 branch.

Commits
-------

21a59ca [Form] Fixed FileType not to throw an exception when bound empty

Discussion
----------

[Form] Fixed FileType not to throw an exception when bound empty

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #6134
Todo: -
License of the code: MIT
Documentation PR: -
@fabpot fabpot closed this as completed Dec 13, 2012
@ghost
Copy link

ghost commented Dec 13, 2012

Thanks 👍 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants