FOSUser:覆盖注册视图以避免csrf和验证未分类的错误消息

时间:2012-12-14 14:27:05

标签: forms symfony override fosuserbundle

我试图覆盖我的html twig视图,希望它能解决验证消息的问题。

html twig文件:

    {% extends "FOSUserBundle::layout.html.twig" %}

    {% block fos_user_content %}


   <form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }}      method="POST" class="fos_user_registration_register">



 <div>
     <label for="fos_user_registration_form_username" class="required">Nom d&#039;utilisateur :</label>
     <input type="text" id="fos_user_registration_form_username" name="fos_user_registration_form[username]" required="required" maxlength="255" pattern=".{2,}" />
 </div>

<div>
    <label for="fos_user_registration_form_email" class="required">Adresse e-mail :</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" class="required">Mot de passe :</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" class="required">Vérification :</label>
    <input type="password" id="fos_user_registration_form_plainPassword_second" name="fos_user_registration_form[plainPassword][second]" required="required" /></div>

<div>
    <input type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}"    />
</div>
  </form>
 {% endblock fos_user_content %}

表单正确显示但未提交。

根据FOSUser捆绑实体,输入名称是否正确? 缺少什么,什么是错的? 如何显示错误? 如何处理CSRF隐藏领域?

1 个答案:

答案 0 :(得分:1)

我解决了我的问题:

 <form action="/projet_etienne_auth/web/app_dev.php/register/"  method="POST"     class="fos_user_registration_register">
      {{ form_errors(form) }}
      {{ form_widget(form._token) }}


<div>
    <label for="fos_user_registration_form_username" class="required">Nom d&#039;utilisateur :</label>

    <input type="text" id="fos_user_registration_form_username" name="fos_user_registration_form[username]" required="required" maxlength="255" pattern=".{2,}" />
</div>

    <div>
        <label for="fos_user_registration_form_email" class="required">Adresse e-mail :</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" class="required">Mot de passe :</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" class="required">Vérification :</label>
        <input type="password" id="fos_user_registration_form_plainPassword_second" name="fos_user_registration_form[plainPassword][second]" required="required" />
    </div>



<div>
    <input type="submit" value="Enregistrer" />
</div>

{{form_widget(form)}}或{{form_rest(form)}}生成了不合适的验证消息或csrf_error。

希望它可以帮助别人...