Skip to content

[Form] ContextErrorException in FileType #25063

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
chihiro-adachi opened this issue Nov 21, 2017 · 3 comments
Closed

[Form] ContextErrorException in FileType #25063

chihiro-adachi opened this issue Nov 21, 2017 · 3 comments

Comments

@chihiro-adachi
Copy link

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.7.38, 3.3.13

In symfony 2.7.38 / 3.3.13, the following warning occurred with FileType.

ContextErrorException in FileType.php line 43:
Warning: Invalid argument supplied for foreach()

It is reproduced with the following code. (I am using Silex)

        $builder = $app['form.factory']->createBuilder();
        $builder->add('file', FileType::class, [
            'multiple' => true,
        ]);

        $form->submit([]);

$event->getData() returns null, so it appears to be warned by foreach ().

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/FileType.php#L38

@Simperfit
Copy link
Contributor

Hi @chihiro-adachi I think this should be handle whenever getData() is null.

Do you want to provide a PR to fix the behaviour ?

@chihiro-adachi
Copy link
Author

@Simperfit
thank you. I'll give it a try.

@xabbuh
Copy link
Member

xabbuh commented Nov 22, 2017

see #25102

nicolas-grekas added a commit that referenced this issue Nov 23, 2017
…achi)

This PR was squashed before being merged into the 2.7 branch (closes #25102).

Discussion
----------

[Form] Fixed ContextErrorException in FileType

| Q             | A
| ------------- | ---
| Branch?       |  2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25063
| License       | MIT
| Doc PR        | --

Fixed an issue that ContextErrorException occurs when multiple is enabled.

Commits
-------

1b408e6 [Form] Fixed ContextErrorException in FileType
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

5 participants