When registering a client I am using a redirect to take the user to another page

cferrufino
Shopify Partner
1 0 0

In my registration form I am using: {%- form 'create_customer', return_to: routes.cart_url -%}

This redirect to take the user to the cart page after registration. When you register for the first time it works fine. The problem I have is that when someone registers with an email that has already been used, it does not show me the error "This email has already been used", but rather it sends me to the cart page and the user does not register.

How can I validate that part so that the "This email has already been used" message is displayed before doing the redirection?

 

Also use this method
<input type="hidden" name="return_to" value="/cart"> and the same thing happens.

I appreciate your help

Reply 1 (1)

PageFly-Theodor
Globetrotter
576 75 87

Hi @cferrufino ,
This is Theodore from PageFly - Shopify Page Builder App.

Here's the solution to prevent redirecting before validation in your Shopify registration form:

Use AJAX with Javascript&colon;

  1. Add an event listener to the form to prevent default submission.
  2. Use fetch with AJAX to submit the form data to /account/create.
  3. Parse the JSON response and check for errors (data.errors).
  4. If errors exist, display them in a designated container (e.g., using innerHTML).
  5. If no errors, redirect to the cart page (window.location.href).


Best regards,
Theodore | PageFly

Please let me know if it works by giving it a Like or marking it as a solution!


PageFly - #1 Page Builder for Shopify merchants.


All features are available from Free plan. Live Chat Support is available 24/7.