I would like to build a form with label and inputs, but the class of them should be different. Code below creates the label for the input with same attr:
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('hours', null ,
array('attr'=>
array(
'placeholder'=>'Working Hours',
'class'=>'ui-spinner-box') ) )
}
In my code above the ui-spinner-box will be outputted for both label and input. It will even put placeholder for its label.
So how to make it create attr for label separately so I can output something like below :
<label class="MYCLASSFOR_LABEL" for="input_id">Hours</label>
<input class="MYCLASSFOR_INPUTS" type="text" id="input_id" name="" value="" >
As mentioned in the documentation:
You can set those attributes in twig template or in form builder:
Twig template:
for symfony 2.1 and newer use:
in the legacy symfony 2.0 it used to be
Form builder