FOSUserBundle (login / register) + AJAX + Symfony2

I installed FOSUserBundleon my website Symfony2and I rewrote the login and registration pages. It works very well, but now I have one more problem:

Creating a pop-up window with a tag AJAXfor registration and registration, working with different routes, controllers, etc.

How to do it in the best way?

My pop up is a simple boot modal login.html.twigfor FOSUserBundle, here is the code modal-bodyfor the login part (I will use the registration form for the registration part):

<div class="modal-body">
    {% trans_default_domain 'FOSUserBundle' %}

    {% block fos_user_content %}
        <form action="{{ path("fos_user_security_check") }}" method="post">
            <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

            <label for="username">{{ 'security.login.username'|trans }}</label>
            <input type="text" id="username" name="_username" value="" required="required" />

            <label for="password">{{ 'security.login.password'|trans }}</label>
            <input type="password" id="password" name="_password" required="required" />
            <br /><br />
            <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans }}" />
        </form>
    {% endblock fos_user_content %}
</div>

I have already searched on StackOverflow and other websites, but did not find the suitable answer I was looking for.

Thank.

+1
1

AJAX

user=$('#username').val();
pass=$('password').val();
$.ajax(
     {
     type: "POST",
     url: "{{ path ('your-rout')}}",
     data: {'user': user,'pass':pass},
      beforeSend: function() {
       },
      success: function(json) {}
});
0

All Articles