stivlo
stivlo

Reputation: 85486

How to set a value in a form in Symfony2?

To set a value in a form programmatically with Symfony2, after a form has been created, I've found that the following way works:

$form_data = $form->getData();
$form_data['name'] = 'new value';
$form->setData($form_data);

This is awkward, isn't there a simpler way like $form->set('name', 'new value'); ?

Upvotes: 1

Views: 755

Answers (1)

AlterPHP
AlterPHP

Reputation: 12727

$form->get('name')->setData('new value');

Upvotes: 5

Related Questions