0

I have got form like that: One input field - Text with name trollName.

namespace Acme\MyBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class myFormType extends AbstractType {
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('trollName','text')
        ;
    }
}

Some controller:

$myForm = $this->createForm(new myFormType()) -> createView();

I want to render this field, but I want to use bootstrap class - form-control

How to modify twig view:

{{ form_widget(myForm.trollName) }}

... to get response like that:

<input type='text' name='trollName' class='form-control'> <!-- form-control class is from boostrap -->
1
  • See the doc Commented Dec 31, 2014 at 14:06

2 Answers 2

1

If you are strating a new project I will suggest you to use Symfony 2.6 which includes Twitter bootstrap.

Take a look here for more details

Sign up to request clarification or add additional context in comments.

Comments

0

For SF version < 2.6, you can do it like this:

example:

{{ form_start(form, {'attr': {'class': 'form-horizontal style-form', 'role': 'form'}}) }}

    <div class="form-group">
        {{ form_label(form.trollName, 'TrollName', {'label_attr': {'class': 'col-md-2 control-label'}}) }}
        <div class="col-md-6">
            {{ form_widget(form.trollName, {'attr': {'class':'form-control'}}) }}
            {{ form_errors(form.trollName) }}
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-6">
            {{ form_widget(form.submit, {'attr': {'class':'btn btn-theme'}}) }}
        </div>
    </div>
{{ form_end(form) }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.