Skip to content

Sending non array causes UnexpectedTypeException #13804

@BruceWouaigne

Description

@BruceWouaigne

Hi guys,

I just notice that, when I send a non array data to a collection form field the ResizeFormListener throws an UnexpectedTypeException before the form validation.

Here is the action

public function indexAction(Request $request)
{
    $form = $this->get('form.factory')->createNamed('', new FooType, null, [
        'method' => 'GET'
    ]);

    $request->query->set('emails', 'a');

    // Throws an exception
    $form->handleRequest($request);

    if ($form->isValid()) {
        die(var_dump('valid'));
    }

    die(var_dump($form->getErrorsAsString()));
}

And the form

class FooType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('emails', 'collection', [
            'type' => 'email'
        ]);
    }

    public function getName()
    {
        return 'foo';
    }
}

Is there anything that I can do to avoid this? By this I mean to get a non valid form instead of an Exception...

I don't really get why https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php#L147 should throws an Exception instead of doing a $data = []; or something.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions