I am using the FOSUserBundle to manage my website users. My goal is to make the login form get displayed in a modal window based on the boostrap framework. Down is my code for the modal window
<div class="modal hide" data-backdrop="static" id="login">
<div class="modal-header"> <a class="close" data-dismiss="modal">×</a>
<h3>Connexion</h3>
</div>
<div class="modal-body" >
</div>
</div>
<a class="btn btn-primary" data-toggle="modal" data-target="#login"
href="{{ path('fos_user_security_login') }}">Sign in</a>
This code works perfectly well if the user does not make any mistake while entring his username and his password. In case of errors, symfony2 redirect me directly to /login page which is the minimalist twig page provided by the bundle FOSUserBundle.
In order to get rid of the problem, my idea consisted in listening to javascript event that will display the window again. This is done through the window.hashchange event. The proposed code for that is:
<script type="text/javascript" src="{{ asset('jquery/1.9.1/jquery.ba-hashchange.min.js')}}"></script>
<script>
$(function() {
// Bind the event.
$(window).hashchange(function() {
// Alerts every time the hash changes!
alert(location.hash);
if(location.hash === "#login"){
$('#login').modal();
}
});
// Trigger the event (useful on page load).
$(window).hashchange();
});
</script>
This was great: throught this code, I become able to display to login modal window if I get to this url /#login.
But, the problem is still not solved yet, because there is a routing problem in symfony. I am afaid to have to rewrite all the bundle to make redirection in the controllers of FOSUserBundle.
Any idea?