Reputation: 500
I have a function, in Symfony2, that creates a form. Then I load it using twig and everything works fine.
The problem is that I would like to add style to each label and each input, separately, and I can only add style to the whole form.
private function createEditForm(Client $entity)
{
$form = $this->createForm(new ClientType(), $entity, array(
'action' => $this->generateUrl('client_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
Could I do it the way I'm doing it or do I have to rebuild the function so it doesn't create the form dynamically from an array?
Thank you.
Upvotes: 1
Views: 940
Reputation: 1678
You can customize the class rendered for example in your ClientType
via something like this:
$builder->add('name' , 'text' , array( 'attr' => array( 'class' => 'nameInputField' ) ) );
Or you can add/override directly in your twig template as such:
{{ form_row(form.name, { 'attr': { 'class': 'nameInputField' }} ) }}
For advanced cases and re-usability refer to the form customization tutorial here:
http://symfony.com/doc/current/cookbook/form/form_customization.html
Upvotes: 4