symfony - Symfony2 FormBuilder: How to add and attribute to multiple form fields -
i want add stylesheet class attribute of fields, not all.
public function buildform(formbuilder $builder, array $options) { $builder ->add('name_short', null, array('attr' => array('class' => 'rtl')) ) ->add('name_long') ->add('profile_education') ->add('profile_work') ->add('profile_political') ->add('twitter') ->add('facebook') ->add('website') ; }
is there simpler way adding attribute array('attr' => array('class' => 'rtl'))
every field?
was looking looping fields , setting attribute after adding field builder.
more (unfortunately there no setoption method in formbuilder):
foreach($builder->all() $key => $value) { $value->setoption('attr', array('class' => 'rtl')); }
thanks pointers.
you can while constructing form. hold field names in array. if need assign different field types, use associative array instead.
public function buildform(formbuilder $builder, array $options) { $fields = array('name_short', 'profile_education', 'profile_work', 'profile_political', 'twitter', 'facebook', 'website'); foreach ($fields $field) { $builder->add($fields, null, array('attr' => array('class' => 'rtl'))); } }
Comments
Post a Comment