php - Symfony adding style to each input field

939

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.

130

Answer

Solution:

You can customize the class rendered for example in yourClientType 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

People are also looking for solutions to the problem: guzzle - How to process (Inserting in db) incoming streaming data in php?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.