简体   繁体   English

覆盖FOSUserBundle Symfony中的注册表格

[英]Override registration form in FOSUserBundle Symfony

I am trying to override the default areas of the fosuserbundle registration form. 我正在尝试覆盖fosuserbundle注册表单的默认区域。 I added all the required fields I wanted through database and customize with the bootstrap cdn. 我通过数据库添加了我想要的所有必填字段,并使用bootstrap cdn进行了自定义。 But when I try to customize the defaults fields of the registration form, I cannot find it in both register_content.html.twig and register.html.twig to edit them. 但是,当我尝试自定义注册表单的默认字段时,在register_content.html.twigregister.html.twig中都找不到它来进行编辑。

register_content.html.twig register_content.html.twig

{% trans_default_domain 'FOSUserBundle' %}

{{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register'}}) }}
    {{ form_widget(form) }}
    <div>

        <input class="btn btn-success" type="submit" id="_submit" name="_submit" value="{{ 'registration.submit'|trans }}" />
    </div>
{{ form_end(form) }}

register.html.twig register.html.twig

{% extends "@FOSUser/layout.html.twig" %}

{% block fos_user_content %}
{% include "@FOSUser/Registration/register_content.html.twig" %}
{% endblock fos_user_content %}

I would like to customize all the following textareas. 我想自定义以下所有文本区域。

  • Email 电子邮件
  • Username 用户名
  • Password 密码
  • Repeat password 重复输入密码

Where can I find the above fields? 在哪里可以找到以上字段?

Thanks in advance. 提前致谢。

You can find its at vendor/friendsofsymfony/user-bundle/Form/Type/RegistrationFormType.php if you want to change its directy 如果要更改其直接性,可以在vendor/friendsofsymfony/user-bundle/Form/Type/RegistrationFormType.php找到它。

 public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
        ->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
        ->add('plainPassword', 'repeated', array(
            'type' => 'password',
            'options' => array('translation_domain' => 'FOSUserBundle'),
            'first_options' => array('label' => 'form.password'),
            'second_options' => array('label' => 'form.password_confirmation'),
            'invalid_message' => 'fos_user.password.mismatch',
        ))
    ;
}

But it better to override the forme type as below in config.yml (create a new formType) 但是最好在config.yml中覆盖以下forme类型(创建一个新的formType)

fos_user:
    # ...
    registration:
        form:
            type: AppBundle\Form\RegistrationType

If you want to override existing FormType then follow that doc: http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html 如果要覆盖现有的FormType,请遵循该文档: http : //symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html

If you want to choose specific fields in html, you can select fields like that: 如果要选择html中的特定字段,则可以选择如下字段:

{{ form_widget(form.email) }}

{{ form_widget(form.username) }}

or 要么

{{ form_widget(form.email, { 'attr': {'class': 'foo'} }) }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM