2016-07-20 17 views
2

私は単純な問題があります。 私はちょうどので、symfonyにチェックボックスウィジェットを作成したい:symfonyでラベルをカスタマイズしてチェックボックスを作成する

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

をしかし、私はこの出力を得る:

<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> 

私はラベルのテキストを変更したいが、PHPでラベルattributをオーバーライドするときに出力されます:

<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> 

私は2つのラベルを持っています。

私が取得したいでしょう:

私はこの bundle(BraincraftedBootstrapBundle)を使用
<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> 

あなたの助けをいただき、ありがとうございます。

<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> 

ただ、フォームウィジェットをレンダリングし、手でラベルを作成します。

+0

フォームテンプレートhttp://symfony.com/doc/current/cookbook/form/form_customization.html –

+0

@dragosteを変更する必要があります。 :D –

+0

http://symfony.com/doc/current/cookbook/form/form_customization.html – pavlovich

答えて

1

は、このようなフォームをレンダリングします。

+0

こんにちは、お返事ありがとうございます。 – Oneill

+1

それはOKですが、symfonyのドキュメントにはこう書かれています: "Bootstrapフォームテーマを使用してレンダリングすると手動でフィールドをチェックし、チェックボックス/ラジオフィールドのform_label()を呼び出しても何も表示されません。ブートストラップ内部のため、ラベルはすでにform_widget()によって表示されています。 – Oneill

関連する問題