Symfony2, How to make a form label class/attr different than its input?

后端 未结 4 891
忘了有多久
忘了有多久 2021-01-30 05:31

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:

 publi         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 06:11

    This may be new, but there's an easy way to do this now:

    $builder
        ->add('hours', null , array(
            'attr'=> 
                array(
                    'placeholder'=>'Working Hours',
                    'class'=>'MYCLASSFOR_INPUTS') 
            ) ,
            'label_attr' => array(
                'class' => 'MYCLASSFOR_LABEL'
            )
        );
    

    The option you're looking for is label_attr.

提交回复
热议问题