Take the 2-minute tour ×

I just started with Symfony2 and I am currently creating a form to edit user data.

I was able to create a select dropdown with this:

$builder->add('department', 'entity', array( 
        'em' => 'default', 
        'class' => 'My\SuperBundle\Entity\Department', 
        'multiple' => false, 
        'required' => true, 
        'query_builder' => function($repo) { 
            return $repo->createQueryBuilder('r')->orderBy('r.name', 'ASC'); 

This is fine if I create a new user, but if I want to edit an existing one, the old value should be preselected (which it isn't). Also for a new user there should be a non-value (or empty) choice at the top so the user is forced to select something.

With the way described at http://symfony.com/doc/current/book/forms.html#embedded-forms I get the name of the current department of that user, but no selectable dropdown list.

Is this possible, and if so, how?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I found http://kurtfunai.com/2012/01/building-forms-in-symfony2.html and now it works the way I want it!

share|improve this answer
add comment

Your Answer


