DarksteelPenguin DarksteelPenguin - 6 months ago 22
PHP Question

Symfony form_login does not work, but http_basic does

I'm trying to implement a login function in my Symfony2 application, using the built-in login functionnality from Symfony.

I can access the /login page fine, but when I type my username and password, and hit login, it just brings me back to the /login page, without any error message.
If I try to connect with the wrong username and/or password, or none, the same thing happens: I get redirected to /login with no error message.

I tried to connect using http_basic, and it worked. So I suppose my users provider is good, but I don't get what prevents the login from working.

login.html.twig

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

{% block title %}Login{% endblock %}

{% block stylesheets %}
{{ parent() }}
{% stylesheets 'bundles/seinput/css/login/*' filter='cssrewrite' %}
<link rel="stylesheet" type="text/css" charset="UTF-8" media="all" href="{{ asset_url }}"/>
{% endstylesheets %}
{% endblock %}

{% block body %}
<form action="{{ path('login') }}" method="post">
<div class="field">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />
</div>
<div class="field">
<label for="password">Password:</label>
<input type="password" id="password" name="_password" />
</div>
<div class="form-button">
<button class="btn btn-success" type="submit">login</button>
</div>
{% if error %}
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% else %}
<div>No error</div>
{% endif %}
<input type="hidden" name="_target_path" value="/" />
</form>
{% endblock %}


edit: Now that the answer is provided, and since the error comes from a single line in the twig file, I removed the other files, to make the question more readable to future readers.

Answer

I see that your form have and action that points to login URL, ┬┐you can try to modify this to login_check?

I think that your problem is near here

<form action="{{ path('login_check') }}" method="post">
Comments