Reputation: 43
I need to set default values for my form. There is code, from my controller:
$form = $this->createFormBuilder()->add('user', new Form\UserType($user))
->add('client', new Form\ClientType($client))
->getForm();
And I have two entites: User & Client. So, how I can set default values from entites?
Upvotes: 1
Views: 2360
Reputation: 8008
I set the default values for my text fields like this
->add('firstname', 'text', array('attr' => array('value' => 'bla')))
for an Entity you can set empty value to false and fill the prefrred_choices array
->add('language', 'entity', array('empty_value' => false, 'preferred_choices' => array('2'), 'class' => 'CPAppUserBundle:Language', ))
Upvotes: 3
Reputation: 1528
In the form classes of each your user and your client class you can set default values like this:
public function configure() {
$this->setDefault('yourfield', $defaultvalue);
}
Upvotes: -2