更改Symfony2 FOSUserBundle注册表单POST参数? [英] Change Symfony2 FOSUserBundle registration form POST parameters?

查看:168
本文介绍了更改Symfony2 FOSUserBundle注册表单POST参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < form action =/ Symfony / web / signup这是FOSUserBundle的注册表单的样子:

/method =POSTclass =fos_user_registration_register>
< div id =fos_user_registration_form>
< input type =hiddenid =fos_user_registration_form__tokenname =fos_user_registration_form [_token]value =c248f3ef17b082803ae9948c03d137c380f0dc24/>
< div>
< label for =fos_user_registration_form_username>用户名:< / label>< input type =textid =fos_user_registration_form_usernamename =fos_user_registration_form [username]required =requiredmaxlength = 255pattern =。{2,255}/>
< / div>
< div>
< label for =fos_user_registration_form_email>电子邮件:< / label>< input type =emailid =fos_user_registration_form_emailname =fos_user_registration_form [email]required =required/>
< / div>
< div>



所以,你可以看到,

 < input type =emailid =fos_user_registration_form_emailname =fos_user_registration_form [email]

主要问题:如何将id更改为id =email之类的名称, = 电子邮件?显然,它必须工作。

在这里你可以看到: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/views/Registration/register_content.html.twig {{form_widget(form)}},但我无法追溯到它发生的地方。我还假设RegistrationFormHandler必须被编辑以支持这些参数。

解决方案

修改RegistrationFormType类中的buildForm函数:

 #FOSUserBundle / Form / Type / RegistrationFormType.php 

类RegistrationController扩展ContainerAware
{

// ...

public function getName()
{
return'fos_user_registration';


$ b

更改 fos_user_registration 无论你想要什么。


This is how the registration form of FOSUserBundle looks like:

<form action="/Symfony/web/signup/" method="POST" class="fos_user_registration_register">
<div id="fos_user_registration_form">
    <input type="hidden" id="fos_user_registration_form__token" name="fos_user_registration_form[_token]" value="c248f3ef17b082803ae9948c03d137c380f0dc24"/>
    <div>
        <label for="fos_user_registration_form_username">Username:</label><input type="text" id="fos_user_registration_form_username" name="fos_user_registration_form[username]" required="required" maxlength="255" pattern=".{2,255}"/>
    </div>
    <div>
        <label for="fos_user_registration_form_email">Email:</label><input type="email" id="fos_user_registration_form_email" name="fos_user_registration_form[email]" required="required"/>
    </div>
    <div>
        <label for="fos_user_registration_form_plainPassword_first">Password:</label><input type="password" id="fos_user_registration_form_plainPassword_first" name="fos_user_registration_form[plainPassword][first]" required="required"/>
    </div>
    <div>
        <label for="fos_user_registration_form_plainPassword_second">Verification:</label><input type="password" id="fos_user_registration_form_plainPassword_second" name="fos_user_registration_form[plainPassword][second]" required="required"/>
    </div>
</div>
<div>
    <input type="submit" value="Register"/>
</div>

So, as you can see,

<input type="email" id="fos_user_registration_form_email" name="fos_user_registration_form[email]"

MAIN QUESTION: How can I change the id to something like id="email" and also the name to something like name="email"? And it has to work, obviously.

Here you can see: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/views/Registration/register_content.html.twig {{ form_widget(form) }}, but I can't trace this to where it goes. I also presume the RegistrationFormHandler would have to be edited to support these parameters.

解决方案

Alter buildForm function in RegistrationFormType class:

# FOSUserBundle/Form/Type/RegistrationFormType.php

class RegistrationController extends ContainerAware
{

   // ...

   public function getName()
   {
       return 'fos_user_registration';
   }

}

Change fos_user_registration to whatever you want.

这篇关于更改Symfony2 FOSUserBundle注册表单POST参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆