Basic form

With v3.0, we have smarter defaults for form styles.

Mopa bootstrap example forms

Associated help text!

Expanded and multiple (inline)

Inline form

Inputs are block level to start. For .form-inline and .form-horizontal, we use inline-block.

FormType Code

// ExampleFormsType.php

<?php
namespace Mopa\Bundle\BootstrapSandboxBundle\Form\Type;

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

class ExampleFormsType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('textField', 'text', array(
                'label' => "Label name",
                'help_block' => 'Associated help text!',
                'attr' => array(
                    'placeholder' => "Some text",
                )
            ))
            ->add('checkboxesInline', 'choice', array(
                'label_render'        => false,
                'help_block'  => 'Expanded and multiple (inline)',
                'multiple'     => true,
                'expanded'     => true,
                'choices'      => array('1' => 'one', '2' => 'two'),
                'widget_type'  => "inline"
            ))
        ;
    }
    public function getName()
    {
        return 'mopa_bootstrap_example_forms';
    }
    public function getButtonValue()
    {
        return ""; # return here the name of the route the form should point to
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(
            array(
                'data_class' => 'Mopa\Bundle\BootstrapSandboxBundle\Form\Model\ExampleFormsData'
            )
        );
    }
}

Template Code

{# MopaBootstrapSandboxBundle:Examples:forms.html.twig #}

{% extends "MopaBootstrapSandboxBundle::layout.html.twig" %}
{% from 'MopaBootstrapBundle::flash.html.twig' import session_flash %}

{% block headline %}Forms Example{% endblock headline %}

{% block content %}
    <div class="col-lg-3">
        <h3>Basic form</h3>
        <p>With v3.0, we have smarter defaults for form styles.</p>
    </div>
    <div class="col-lg-9">
        <form class="well bs-example ">
              {{ form_widget(form) }}
              <button type="submit" class="btn">Submit</button>
        </form>
    </div>
</div>
  <h3>Inline form</h3>
  <div class="row">
      <div class="col-lg-3">
        <p>Inputs are block level to start. For <code>.form-inline</code> and <code>.form-horizontal</code>, we use inline-block.</p>
      </div>
      <div class="col-lg-9">
        <form class="well bs-example form-inline">
            {{ form_widget(inlineform) }}
            <button type="submit" class="btn">Submit</button>
        </form>
      </div>
{% endblock content %}

{% set showTemplate = _self %}{% set showForm = formType %}
Fork me on GitHub