Login and register in same page with FOSUserBundle

我只是一个虾纸丫 提交于 2019-12-12 03:34:33

问题


I am using login and register in same page with fosuserBundle in my Symfony application.Login work perfect but register does not work.When I click button register I redirected to login.No registration in my database.

This is my login.html.twig:

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

        {% trans_default_domain 'FOSUserBundle' %}

           {% block fos_user_content %}
         {% if error %}
           <div>{{ error.messageKey|trans(error.messageData, 'security') }}
           </div>
       {% endif %}

       <div class="login-container">

          <div class="position-relative">
            <div id="login-box" class="login-box visible widget-box no-border">
              <div class="widget-body">
                <div class="widget-main">
                  <h4 class="header blue lighter bigger">
                    <i class="ace-icon fa fa-coffee green"></i>
                    Please Enter Your Information
                  </h4>

                  <div class="space-6"></div>

                  <form method="post" action="{{ path("fos_user_security_check") }}">
                  <label class="block clearfix">
                        <span class="block input-icon input-icon-right">

                          <input type="text" name="_username" class="form-control" placeholder="{{ 'security.login.username'|trans }}" required="required" />
                          <i class="ace-icon fa fa-user"></i>
                        </span>
                      </label>

                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">

                          <input type="password" name="_password" class="form-control" value="" placeholder="{{ 'security.login.password'|trans }}" required="required" />
                          <i class="ace-icon fa fa-lock"></i>
                        </span>
                      </label>

                      <div class="space"></div>

                      <div class="clearfix">
                        <label class="inline">
                          <input type="checkbox" class="ace" name="_remember_me" value="{{ 'security.login.remember_me'|trans }}"/>

                          <span class="lbl"> Remember Me</span>
                        </label>

                        <button type="submit" id="_submit" name="_submit"class="width-35 pull-right btn btn-sm btn-primary">
                          <i class="ace-icon fa fa-key"></i>
                          <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
                            {{ 'security.login.submit'|trans }}   
                        </button>

                      </div>

                      <div class="space-4"></div>

                  </form>

                </div><!-- /.widget-main -->

                <div class="toolbar clearfix">
                  <div>
                    <a href="#" data-target="#signup-box" class="user-signup-link">
                      I want to register
                      <i class="ace-icon fa fa-arrow-right"></i>
                    </a>
                  </div>
                </div>
              </div><!-- /.widget-body -->
            </div><!-- /.login-box -->
            {{ render(controller('FOSUserBundle:Registration:register')) }}
          </div><!-- /.position-relative -->
      </div>

        {% endblock fos_user_content %}

This is my register.html.twig:

       <div id="signup-box" class="signup-box widget-box no-border">
              <div class="widget-body">
                <div class="widget-main">
                  <h4 class="header green lighter bigger">
                    <i class="ace-icon fa fa-users blue"></i>
                    New User Registration
                  </h4>

                  <div class="space-6"></div>
                  <p> Enter your details to begin: </p>
                  {% block fos_user_content %}
                  {% include "FOSUserBundle:Registration:register_content.html.twig" %}
                                  {% endblock fos_user_content %} 
                </div>

                <div class="toolbar center">
                  <a href="#" data-target="#login-box" class="back-to-login-link">
                    <i class="ace-icon fa fa-arrow-left"></i>
                    Back to login
                  </a>
                </div>
              </div><!-- /.widget-body -->
            </div><!-- /.signup-box -->

This is my register_content.html.twig:

             {% trans_default_domain 'FOSUserBundle' %}

              {{ form_start(form, {'attr': {'class': 'form-horizontal'} },{'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register'}}) }}


                    <fieldset>
                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">
                        {{ form_widget(form.email,{'attr': {'class': 'form-control'} }) }}

                          <i class="ace-icon fa fa-envelope"></i>
                        </span>
                      </label>

                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">
                         {{ form_widget(form.username,{'attr': {'class': 'form-control'} }) }}
                          <i class="ace-icon fa fa-user"></i>
                        </span>
                      </label>

                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">
                          {{ form_widget(form.plainPassword.first,{'attr': {'class': 'form-control'} }) }}
                          <i class="ace-icon fa fa-lock"></i>
                        </span>
                      </label>

                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">
                          {{ form_widget(form.plainPassword.second,{'attr': {'class': 'form-control'} }) }}
                          <i class="ace-icon fa fa-retweet"></i>
                        </span>
                      </label>

                      <label class="block">
                        <input type="checkbox" class="ace" />
                        <span class="lbl">
                          I accept the
                          <a href="#">User Agreement</a>
                        </span>
                      </label>

                      <div class="space-24"></div>

                      <div class="clearfix">
                        <button type="reset" class="width-30 pull-left btn btn-sm">
                          <i class="ace-icon fa fa-refresh"></i>
                          <span class="bigger-110">Reset</span>
                        </button>

                        <input type="submit" value="{{ 'registration.submit'|trans }}" />
                      </div>
                    </fieldset>
                  {{ form_end(form) }}

回答1:


I solved my problem by deleting {'attr': {'class': 'form-horizontal'} } in my register_content.html.twig.



来源:https://stackoverflow.com/questions/36311189/login-and-register-in-same-page-with-fosuserbundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!