I got a Form class with an object field not showing in it:
->add('client', 'entity', array( 'class' => 'MyBundle:Client', 'property' => 'name', 'empty_value' => 'Select...', 'query_builder' => function(EntityRepository $er) { return $er->createQueryBuilder('c') ->orderBy('c.name', 'ASC'); }, 'mapped' => false, ))
which I create as follows:
$form = $this->createForm(new MyType(), $entity, array('action' => $this->generateUrl('my_action')) );
How to set the default value? tried this but didn't work:
'data' => 23423, // id in table 'data' => 'Client name' $form->setDefault('client', 'Client name'); // in controller
Please note that this is not a displayed field.
source share