V
V
VoLandMonk2019-09-22 00:56:16
symfony
VoLandMonk, 2019-09-22 00:56:16

Sumfomy form builder how to change label for?

I create a form through FormBuilder,
there is a checkbox, man / woman (woman), the form builder symphony creates its own label for the input, are there options to change it ???

<label for="registration_form_gender" class="required">Gender</label>

on the
<label for="ТУТ Я ХОЧУ СВОЙ FOR!!!!!!!!!!" class="required">Gender</label>

Tried like this:
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('firstname', Text::class)
            ->add('lastname', Text::class)
            ->add('email', EmailType::class)
            ->add('birthday', Date::class)
            ->add('gender', CheckboxType::class, [
                'label'    => ['for' => 'ТУТ Я ХОЧУ СВОЙ FOR!!!!!!!!!!'],
                'required' => false,])

does not work. There are no such details in the documentation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bkosun, 2019-09-22
@bkosun

Use the option label_attrto set custom attributes for the label:

$builder->add('gender', CheckboxType::class, [
        'label_attr' => ['for' => 'CUSTOM_FOR',],
    ]);

https://symfony.com/doc/current/reference/forms/ty...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question