Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create checkbox with customise label in symfony

I have a simply problem. I want just to create a checkbox widget with symfony so:

 $builder->add("terms", CheckboxType::class, array('label'=>false));

But i obtain this output:

<div class="checkbox">
    <label for="fos_user_registration_form_terms" class="required">
        <input id="fos_user_registration_form_terms" name="fos_user_registration_form[terms]" required="required" class=" checkbox" value="1" type="checkbox">
                        Terms
     </label>
</div>

I want change text of label but when override the label attribut in PHP the output is:

<div class="checkbox">
    <label for="fos_user_registration_form_terms" class="required">
        <div class="checkbox">
            <label for="fos_user_registration_form_terms" class="required required">
              <input id="fos_user_registration_form_terms" name="fos_user_registration_form[terms]" required="required" class=" checkbox" value="1" type="checkbox">
                        test
             </label>
        </div>
        test
     </label>
</div>

I have two label.

I will want obtain:

<div class="checkbox">
<label for="fos_user_registration_form_terms" class="required">
    <input id="fos_user_registration_form_terms" name="fos_user_registration_form[terms]" required="required" class=" checkbox" value="1" type="checkbox">
                My label for accept terms with <a> tag   

 </label>

I use this bundle (BraincraftedBootstrapBundle)

Thank you for your help.

like image 837
Oneill Avatar asked Dec 11 '25 06:12

Oneill


1 Answers

Render form like this:

<div class="checkbox">
<label for="fos_user_registration_form_terms" class="required">
    {{form_widget(form.terms)}}
    My label for accept terms with 
    <a> tag   </a>

 </label>
</div>

Just render form widget and create label by hand.

like image 167
M Gholami Avatar answered Dec 12 '25 18:12

M Gholami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!