M4xell
M4xell

Reputation: 321

Symfony 2 + Bootstrap

How can I adapt my form to implement bootstrap ?

My function for create form is:

private function createCreateForm(User $entity)
{

    $form = $this->createFormBuilder($entity, array(
        'action' => $this->generateUrl('user_create'),
        'method' => 'POST',
    ))
    ->add('username')
    ->add('email')
    ->add('password', 'repeated', array(
       'first_name'  => 'password',
       'second_name' => 'confirm',
       'type'        => 'password',
    ))
    ->add('submit', 'submit', array('label' => 'Create'))
    ->getForm();
    return $form;
}

My views is

{{ form_start(form) }}
    {{ form_row(form.username, { 'attr': {'class': 'form-control', 'placeholder': 'Imię oraz nazwisko'} }) }}
    {{ form_row(form.password, { 'attr': {'class': 'form-control', 'placeholder': 'Password'} }) }}

It is working for username but not for the password, some sugestion ? How can i create our own form ?

My bootstrap:

<form action="#" class="form-horizontal">
    <div class="form-body">
        <div class="form-group">
            <label  class="col-md-3 control-label">NAME</label>
            <div class="col-md-4">
                <input type="text" class="form-control" placeholder="NAME
            </div>
        </div>
    <div class="form-actions fluid">
        <div class="col-md-offset-3 col-md-9">
            <button type="submit" class="btn blue">Add</button>
            <button type="button" class="btn default">Anuluj</button>                              
        </div>
    </div>
</form>

Upvotes: 0

Views: 1636

Answers (1)

Pi Wi
Pi Wi

Reputation: 1085

Use Mopa Bootstrapbundle https://github.com/phiamo/MopaBootstrapBundle

In your controller:

 $this->createForm(
      MyFormType(),
      $entity,
      array('attr' => array('class' => 'form-horizontal'))
 );

Upvotes: 2

Related Questions