Reputation: 1
Just wanted to know how I can separate the textbox from the label when creating a form in html twig using formbuilder? The form works fine, but I want to align each new textbox and the text beneath the previous so that it doesn't look as sloppy. Is there a way I can render the form, then style it? I'm using php to create the form with formBuilder, and rendering it with twig.
the php for creating the form looks like this:
$form = $this->createFormBuilder(array('csrf_protection' => false))
->add('username','text', array('label'=>'Username/Alias'))
->add('password','password',array('label'=>'Password'))
->add('ve','text',array('label'=>'Verification code'))
->getForm() ;
$request= $this->getRequest();
And the twig looks like so:
<form action="{{path('myBundle_login')}}" method="post" enctype={{form_enctype(form)}}>
// the form_enctype(form) is the form that is sent through
{{ form_errors(form) }}
{{ form_widget(form) }}
{{ form_rest(form) }}
but i just want it neatly spaced... please help.
Upvotes: 0
Views: 3695
Reputation: 1422
if you want a common style for all forms, apply a common css like below
form div label
{
/*your css here*/
}
form div input
{
/*your css here*/
}
and if you want to style each one as per your wish
<div>
{{ form_errors(form.name) }}
<div>
<div>
{{ form_label(form.name) }}
</div>
</div>
<div>
<div>
{{ form_widget(form.name,{'attr': {'class': 'yourclassname'} }) }}
</div>
</div>
</div>
this will neatly space your form
Upvotes: 1
Reputation: 1160
This page can help you http://symfony.com/doc/current/reference/forms/twig_reference.html#form-row-form-name-variables
specialy this two functions form_row(form.name)
and `form_label(form.name)
Upvotes: 1