php - 在 symfony 中创建带有自定义标签的复选框

标签 php twitter-bootstrap twitter-bootstrap-3 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 中覆盖标签属性时,输出是:

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

我有两个标签。

我要得到:

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

我用这个bundle (BraincraftedBootstrapBundle)

感谢您的帮助。

最佳答案

像这样渲染表单:

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

只需渲染表单小部件并手动创建标签。

关于php - 在 symfony 中创建带有自定义标签的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38476635/

相关文章:

html - bootstrap 3 - 响应表布局到每个 td 在新行上的位置

html - 导航栏中的引导切换不起作用

php - 如何在子域重定向后禁用与 htaccess 的直接链接?

php - PHP 如何与 Apache 交互?

angular - ng-bootstrap 不工作如果 'ngb-xx' 是一个 Angular 组件,那么验证它是这个模块的一部分

html - 删除行之间的边距

html - 将水平制表符从 Bootstrap 3 转换为 Bootstrap 4

java - 通过 Rest API 设置帐户和自定义模块之间的关系 SuiteCRM

php - 如何为表中的每一行创建一个编辑选项?

html - 伪元素不适用于 Bootstrap Modal