cms
cms copied to clipboard
Registration form password validation shows no error
Bug description
When your password is invalid there is no error shown.
How to reproduce
Register with 1234 as password.
{{ user:register_form redirect="/account/dashboard?message=register" }}
{{ if errors }}
<div class="p-4 mt-8 text-white bg-red-700">
{{ errors }}
{{ value }}<br>
{{ /errors }}
</div>
{{ /if }}
{{ /user:register_form }}
// Output
<div class="p-4 mt-8 text-white bg-red-700">
</div>
Logs
No response
Versions
Statamic 3.2.33 Pro Laravel 8.83.1 PHP 8.0.12
Installation
Fresh statamic/statamic site via CLI
Additional details
No response
Try to customize password validation rules maybe that will help: https://statamic.dev/tags/user-register_form#password-rules
I've got the same issue and setting the password rules doesn't seem to help either.
The error object just stays empty, but the user fails to be registered.
I did some extra digging into this - the issue is quite deep within the antlers template engine I think. I didn't do a minimal replication on this, but I've included the relevant parts of my codebase for replication.
When debugging this, when the form is parsed, the "errors" variable is set correctly.
vendor/statamic/cms/src/Auth/UserTags.php:153

{{ user:register_form class="space-y-6" redirect="/dashboard?registered=true" }}
...
<div>
<div>
<input id="remember-me" name="remember-me" type="checkbox">
<label for="remember-me"> Remember me </label>
</div>
</div>
{{ get_errors }} <br> <!-- get_errors -->
{{ errors | to_json }} <br> <!-- errors -->
{{ if errors }}
<div>
{{ errors }}
{{ value }}<br>
{{ /errors }}
</div>
{{ /if }}
<div>
<button type="submit">
Register
</button>
</div>
{{ /user:register_form }}
Resulting HTML (I did note that there is no closing form bracket, is that is expected behaviour?)
<form method="POST" action="http://127.0.0.1/!/auth/register">
<input type="hidden" name="_token" value="...">
<input type="hidden" name="_redirect" value="/dashboard?registered=true" />
...
<div>
<div>
<input id="remember-me" name="remember-me" type="checkbox">
<label for="remember-me"> Remember me </label>
</div>
</div>
<br> <!-- get_errors -->
{} <br> <!-- errors -->
<div>
<button type="submit">
Register
</button>
</div>
I think this is related to the session not being available inside the antlers rendering engine (for an unknown reason). If I do a "session:dump" it dumps the session correctly, but as soon as I do a "session:errors" it does not.
Anyway, I wrote a workaround for this. This only works when using the new Antlers parser as it relies on inline PHP
{{? $errors_fixed = collect(view()->shared('errors')->getBag('user.register')?->toArray() ?? [])->flatten(); ?}}
{{ if errors_fixed }}
<div class="text-red text-sm">
{{ errors_fixed }}
{{ value }}<br>
{{ /errors_fixed }}
</div>
{{ /if }}
This seems to be working for me on the latest version of Statamic:
{{ user:register_form }}
{{ if errors }}
<div class="bg-red-500 text-white rounded-md px-4 py-2 mb-8">
{{ errors }}
{{ value }}<br>
{{ /errors }}
</div>
{{ /if }}
<!-- Form fields ... -->
{{ /user:register_form }}
I'm going to close this issue now. If you're still experiencing this issue, please leave a comment and we can take another look.