formie icon indicating copy to clipboard operation
formie copied to clipboard

User not saved due to validation error.

Open hassanmah opened this issue 1 year ago • 3 comments

Question

Hi,

I'm using the Craft register form with Formie, when a user with an existing account tries to sign up I get an error in the logs "User not saved due to validation error.", on the frontend the error displays as "400: Error creating account."

Is there a way of having more accurate messages such as "User already exists" in this case?

Thanks

Additional context

No response

hassanmah avatar Feb 25 '24 23:02 hassanmah

If you're using the Craft registration form then the templating and error-handling is totally up to you, as you're hitting the users/save-user action endpoint with Craft itself. Might be worth checking the error templating on the sample templates

engram-design avatar Feb 27 '24 13:02 engram-design

@engram-design Just reopening this one

I've created a registration form in Formie and mapped a user object to it

I get all the errors like "Password must be 6 characters" and "Field is required"

But when a user who tries to sign up using an email that already exists I get the generic formie error

If I use the craft template above without formie, I get the error "an account with [email protected] already exists"

How can I still use Formie and get the above error?

Thanks

hassanmah avatar Apr 22 '24 14:04 hassanmah

If you're using the Craft registration form then there should be no difference with how their errors are shown. Formie will only trigger client-side validation for required fields, or a minimum character.

For server-side checks like whether the email exists already, you need to include Craft's template checks.

{% macro errorList(errors) %}
  {% if errors %}
    {{ ul(errors, {class: 'errors'}) }}
  {% endif %}
{% endmacro %}

{{ user ? _self.errorList(user.getErrors('email')) }}

engram-design avatar Apr 25 '24 06:04 engram-design