My custom login form doesn't work, what am I missing?
Created 6 years ago by araneaI am trying to replace the login form with a BS4 version, but for some reason it just keeps redirecting back to the index without being logged in. However when I render the form as {{ form('login').redirect(request_get('redirect', '/'))|raw }}
it works fine, but when I want to render the inputs myself it does not, my twig-template is as follows:
{% extends layout('users') %}
{% block content %}
<div class="row justify-content-center">
<div class="col-lg-6">
<div class="card">
<div class="card-header">
{{ trans('aranea.theme.frontend::message.users.login') }}
</div>
<div class="card-body">
{% set form = form('login').fields({
'email': {
'placeholder': trans('aranea.theme.frontend::field.email.placeholder'),
'type': 'anomaly.field_type.email',
'required': true
},
'password': {
'placeholder': trans('aranea.theme.frontend::field.password.placeholder'),
'type': 'anomaly.field_type.text',
'required': true,
'config': {
'type': 'password'
}
},
'remember_me' : {
'type': 'anomaly.field_type.boolean',
'config': {
'mode': 'checkbox',
'label': trans('aranea.theme.frontend::message.users.remember_me')
}
}
}).redirect(request_get('redirect', '/')).get %}
{{ form.open|raw }}
<div class="row mb-2">
<label class="col-3 col-form-label">{{ trans('aranea.theme.frontend::field.email.name') }}</label>
<div class="col-9">{{ form.fields.email.input|raw }}</div>
</div>
<div class="row mb-2">
<label class="col-3 col-form-label">{{ trans('aranea.theme.frontend::field.password.name') }}</label>
<div class="col-9">{{ form.fields.password.input|raw }}</div>
</div>
<div class="row">
<div class="col-9 offset-3">
{{ form.fields.remember_me|raw }}
</div>
</div>
<div class="mt-2">
<button name="action" type="submit" class="btn btn-primary pull-right">
<i class="fa fa-key fa-fw"></i> {{ trans('aranea.theme.frontend::button.login.name') }}
</button>
<a href="{{ url_route('anomaly.module.users::password.forgot') }}">
{{ trans('anomaly.module.users::message.forgot_password') }}
</a>
</div>
{{ form.close|raw }}
</div>
</div>
</div>
</div>
{% endblock %}
I did confirm the inputs match those generated when I just render the form and they are verbatim. Am I missing something obvious?
Ryan pointed me in the right direction .. the problem was the redefining of the fields. Removing the field definitions and just creating the placeholders on the inputs themselves, like:
{{ form.fields.password.setPlaceholder(trans('aranea.theme.frontend::field.password.placeholder')).input|raw }}
solved my problem.
Why are you re-defining the fields?
Should be all you need for the proceeding code. I don't think the
get
requires()
but I added it in my example just cause.Are you being logged in at all? Or just no-error / no-action?