3

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.

5
  • You need to modify form template symfony.com/doc/current/cookbook/form/form_customization.html Commented Jul 20, 2016 at 8:59
  • @dragoste you beat me to it! :D Commented Jul 20, 2016 at 9:09
  • Also symfony.com/doc/current/cookbook/form/form_customization.html Commented Jul 20, 2016 at 9:27
  • Because you use $builder->add("terms", Symfony defaults to use the quoted string in the add method; in your case "terms", and capitalizes the first letter. Question for you: Is the label you want to use in a file? Above you show with an <a> tag. Do you want to show a large amount of HTML text? Commented Jul 20, 2016 at 16:26
  • Hello, thank you for your answers i want juste to link to my CGV page. Commented Jul 21, 2016 at 8:50

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It's Ok but the documentation of symfony say this: "When you use the Bootstrap form themes and render the fields manually, calling form_label() for a checkbox/radio field doesn't show anything. Due to Bootstrap internals, the label is already shown by form_widget()."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.