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
Comments
I confirm this issue. |
This behaviour happened on my application after SF v2.1.3 -> v2.1.4 update, I think due 2fe04e1 changes. Es: $builder->add('file', 'file', array('data_class' => null)); |
@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! |
@andreadelfino ... Nevermind. I just realized I had commented out my NotNull constraint while testing. |
@bschussek can you please have a look. this makes upload forms kinda useless. |
Since this update, I've got a 500 error instead of validation failure when I try to post a form without a required file. |
Confirmed. |
I have the same issue, with the last version. It will be fixed? |
Fixed in the referenced PR. |
Thanks!
|
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: -
Thanks 👍 ! |
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().
The text was updated successfully, but these errors were encountered: