2

我想在 fosuserbundle 注册表单中使用引导程序样式。并且登录不能覆盖,但是由于注册表单使用“{{ form_widget(form) }}”,所以我不能覆盖它,我使用 symfony2.2,我也测试使用表单主题,像这样

{% block form_row %}
{% spaceless %}
<div class="control-group">
    {{ form_label(form, label|default(null),{ 'attr': {'class': 'control-label'} }) }}
    {{ form_errors(form) }}
    <div class="controls">{{ form_widget(form) }}</div>
</div>
{% endspaceless %}
{% endblock form_row %}

在表单模板中,代码是

{% form_theme form with '@user/form/fields.html' %}
{% trans_default_domain 'FOSUserBundle' %}
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register form-horizontal form-box">
    {{ form_widget(form) }}
    <div>
        <input type="submit" value="{{ 'registration.submit'|trans }}" />
    </div>
</form>

但它输出这个

  |form action="/register/"  method="POST" class="fos_user_registration_register form-horizontal form-box"|
        |div id="fos_user_registration_form"|
            |div class="control-group"|
                |label for="fos_user_registration_form_username" class="required"|用户名:|/label|
                |div class="controls"|
                    |input type="text" id="fos_user_registration_form_username" name="fos_user_registration_form[username]" required="required" /|    
                |/div|
            |/div|
            |div class="control-group"|
                |label for="fos_user_registration_form_email" class="required"|电子邮箱:|/label|
                |div class="controls"|
                    |input type="email" id="fos_user_registration_form_email" name="fos_user_registration_form[email]" required="required" /|    
                |/div|
            |/div|
            |div class="control-group"|
                |label for="fos_user_registration_form_plainPassword_first" class="required"|密码:|/label|
                |div class="controls"|
                    |input type="password" id="fos_user_registration_form_plainPassword_first" name="fos_user_registration_form[plainPassword][first]" required="required" /|    
                |/div|
            |/div|
            |div class="control-group"|
                |label for="fos_user_registration_form_plainPassword_second" class="required"|确认密码:|/label|
                |div class="controls"|
                    |input type="password" id="fos_user_registration_form_plainPassword_second" name="fos_user_registration_form[plainPassword][second]" required="required" /|    
                |/div|
            |/div|
            |input type="hidden" id="fos_user_registration_form__token" name="fos_user_registration_form[_token]" value="622a4c73bfc48b4944c5b97ff4fc46c7fa8e9e91" /|    
        |/div|
        |div|
            |input type="submit" value="注册" /|    
        |/div|
    |/form|

这不是我想要的,所以我能为它做些什么?谢谢!

4

3 回答 3

0

试试看:

https://symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html FOS 用户捆绑将文档移至 symfony.com 文档。

编辑:更新链接

于 2013-06-02T13:11:06.243 回答
0

您可以渲染表单的每个部分而不是 form_widget(form)

{% form_theme form with '@user/form/fields.html' %}

{{ form_errors(form) }}

{{ form_label(form.username) }}
{{ form_widget(form.username) }}
{{ form_errors(form.username) }}

{{ form_label(form.email) }}
{{ form_widget(form.email) }}
{{ form_errors(form.email) }}

{{ form_label(form.plainPassword.first) }}
{{ form_widget(form.plainPassword.first) }}
{{ form_errors(form.plainPassword.first) }}

{{ form_label(form.plainPassword.second) }}
{{ form_widget(form.plainPassword.second) }}

{{ form_rest(form) }}

更多信息在这里:

https://github.com/FriendsOfSymfony/FOSUserBundle/issues/1077

于 2017-02-18T12:59:49.150 回答
0

你可以做 :

<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST">
<div class="form-group" id="fos_user_registration_form">
    {{ form_widget(form.email, { 'attr': {'class': 'form-control', 'placeholder': 'form.email'|trans } }) }}
    {{ form_errors(form.email) }}

    {{ form_widget(form.username, { 'attr': {'class': 'form-control', 'placeholder': 'form.username'|trans } }) }}
    {{ form_errors(form.username) }}

    {{ form_widget(form.plainPassword.first, { 'attr': {'class': 'form-control', 'placeholder': 'form.password'|trans } }) }}
    {{ form_errors(form.plainPassword.first) }}

    {{ form_widget(form.plainPassword.second, { 'attr': {'class': 'form-control', 'placeholder': 'form.password_confirmation'|trans } }) }}
    {{ form_errors(form.plainPassword.second) }}

    {{ form_rest(form) }}

</div>
<div>
    <input class="btn btn-lg btn-primary btn-block" type="submit" value="{{ 'registration.submit'|trans }}">
</div>

于 2018-01-13T13:31:19.077 回答