This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

How to Dynamically Generate Forms based on user Data

This forum is for non code-based questions, best practises, IDEs, version control tools, work opportunities, etc.

How to Dynamically Generate Forms based on user Data

by stoneisonline » Wed Aug 07, 2013 5:21 pm

Hello!
I hope someone can help me:

I tried to do this but it doesn't work.
http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html#how-to-dynamically-generate-forms-based-on-user-data

I always get the Error:
Fatal Error: Object of class Doctrine\ORM\PersistentCollection could not be converted to string in \vendor\symfony\symfony\src\Symfony\Component\Translation\IdentityTranslator.php line 62

in my form builder function

$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function(FormEvent $event) use($user, $factory){
$form = $event->getForm();

$formOptions = array(
'label' => "Standort",
'class' => 'igapSomaMitarbeiterdatenbankBundle:User',
'multiple' => false,
'expanded' => false,
'property' => 'standorte',
'auto_initialize'=>false,
'query_builder' => function(EntityRepository $er) use ($user) {
return $er->createQueryBuilder('u')
->where('u.id = :owner')
->setParameter('owner',$user);
},
);

// create the field, this is similar the $builder->add()
// field name, field type, data, options
$form->add($factory->createNamed('standorte', 'entity', null,$formOptions));
}
);

Standorte is a many to many connection to User.

so i hope there is an easy solution for this.
THANK YOU
stoneisonline
Junior Member
 
Posts: 2
Joined: Wed Aug 07, 2013 5:12 pm