0
votes

I have the next form in Symfony 2.7:

$form = $this->createFormBuilder($entity)
            ->add('laboratorio',null, array('required'=>false)->getForm();

"laboratorio" is a field of type entity. But when I submit the form whitout select a value I got the next error:

An exception occurred while executing 
'SELECT n0_.id AS id0, n0_.codigo AS codigo1,
n0_.nombre AS nombre2 FROM nom_laboratorio 
n0_ WHERE n0_.id IN (?)' with params [""]:

I think that Symfony should not try to find the entity by his id when the optional field is blank.

Even I try whith $this->submit($request,true) instead of $this->handleRequest($request) in the controller but nothing change.

There is something I am ignoring?

1

1 Answers

0
votes

Please try to use the empty_data option.

$form = $this->createFormBuilder($entity)
    ->add('laboratorio',null, array(
        'required'    => false,
        'placeholder' => 'Choose the laboratorio',
        'empty_data'  => null,
    )->getForm();