Custom form redirection breaks form validation

Hello,

I have a problem with custom redirection on forms on my theme (from dawn theme), when i add the “return_to” tag to a form (register form for exemple), custom redirection work well but it skips the form validation (the redirection occurs in all cases, even when errors are present and the account has not been created). Does anyone have an idea to fix the problem ?
Thanks for your help.

Thanks for the answer, but it seem to doesn’t work, in fact when i add the form like that :

{% form 'create_customer' %}

After submitting it, i’m automatically redirect to the home page (default register form behavior (cf shopify doc), and this redirection happened before this code :

{%- if form.posted_successfully? -%}
  
{%- endif -%}​

have you any idea, on how to fix it ?

Thanks for your help !

PS :

Register form default behavior :

Hi, @EnzoLC ,

The code should be work. Because It working for my cases. I think you are missing something else. Could I ask you for the whole code. So I can send you the modified version of the code.

Thanks.

Of Course, there is the code of my main-register.liquid
Thanks !

{{ 'customer.css' | asset_url | stylesheet_tag }}

{% # esthetic-ignore-start %}
{%- style -%}
  .section-{{ section.id }}-header-color {
    color: {{ section.settings.form_color_scheme.settings.header }};
  }
{%- endstyle -%}
{% # esthetic-ignore-end %}

  

    

      

        
          
          

{{ section.settings.text-login-back-website }}

        
        
      

      
        

          
        

        ##### {{ section.settings.text-login-title }}
        {% form 'create_customer'
          , class: "tw-w-full"
        %}

          {%- if form.posted_successfully? -%}
            
          {%- endif -%}

          

            {{ form.errors | default_errors }}
          

          
            
            
          

          
            
            
          

          
            
            
          

          
            
            
          

          
            ##### {{ section.settings.text-register-information-title }}
            

{{ section.settings.text-register-information-message }}

          

          
            
              
              

{{ section.settings.text-register-button-back }}

            
            
          

        {% endform %}
      

    

  

  
    

    

    
      
    

    
      {% for block in section.blocks %}
        {% if block.type == 'advantages' %}
          

            ##### 
              {{ block.settings.text-title-advantages }}
            
            

{{ block.settings.textarea-advantages }}

          

        {% endif %}
      {% endfor %}
      
      
      

        
      

    

  

{% schema %}
  {
    "name": "t:sections.main-register.name",
    "settings": [
      {
        "type": "header",
        "content": "Custom text",
        "info": "If you need a back to line, you can use this balise 
"
      },
      {
        "type": "text",
        "id": "text-login-back-website",
        "label": "Back to website title",
        "default": "Retour au site"
      },
      {
        "type": "text",
        "id": "text-login-title",
        "label": "Login title",
        "default": "Rejoindre le club"
      },
      {
        "type": "text",
        "id": "text-register-information-title",
        "label": "Information title",
        "default": "Parrainage"
      },
      {
        "type": "text",
        "id": "text-register-information-message",
        "label": "Information message",
        "default": "Pour adhérer au Club, vous devez obligatoirement avoir une personne qui vous a recommandé."
      },
      {
        "type": "header",
        "content": "Footer button"
      },
      {
        "type": "text",
        "id": "text-register-button-back",
        "label": "Button back",
        "default": "Retour"
      },
      {
        "type": "text",
        "id": "text-register-button-confirm",
        "label": "Button confirm",
        "default": "Continuer"
      },
      {
        "type": "color_scheme",
        "id": "form_color_scheme",
        "label": "form colors",
        "default": "scheme-2432f7e6-8bee-4498-ba7d-8e410826ace2"
      },
      {
        "type": "color_scheme",
        "id": "advantages_color_scheme",
        "label": "advantages colors",
        "default": "scheme-3"
      }
    ],
    "blocks": [
      {
        "name": "Advantages",
        "type": "advantages",
        "settings": [
          {
            "type": "text",
            "id": "text-title-advantages",
            "label": "Advantages Title"
          },
          {
            "type": "textarea",
            "id": "textarea-advantages",
            "label": "Advantages Text"
          }
        ]
      }
    ]
  }
{% endschema %}

Hi @EnzoLC

Thanks for providing the full code. Here is the modified version of the full code. You can find a line of text “change the URL”. replace the URL you that want to redirect. This is for only the code you provided, It should no use for other form.

{{ 'customer.css' | asset_url | stylesheet_tag }}

{% # esthetic-ignore-start %}
{%- style -%}
  .section-{{ section.id }}-header-color {
    color: {{ section.settings.form_color_scheme.settings.header }};
  }
{%- endstyle -%}
{% # esthetic-ignore-end %}

  

    

      

        
          
          

{{ section.settings.text-login-back-website }}

        
        
      

      
        

          
        

        ##### {{ section.settings.text-login-title }}
        {% form 'create_customer'
          , class: "tw-w-full", return_to: routes.account_register_url
        %}

          {%- if customer -%}
            
          {%- endif -%}

          

            {{ form.errors | default_errors }}
          

          
            
            
          

          
            
            
          

          
            
            
          

          
            
            
          

          
            ##### {{ section.settings.text-register-information-title }}
            

{{ section.settings.text-register-information-message }}

          

          
            
              
              

{{ section.settings.text-register-button-back }}

            
            
          

        {% endform %}
      

    

  

  
    

    

    
      
    

    
      {% for block in section.blocks %}
        {% if block.type == 'advantages' %}
          

            ##### 
              {{ block.settings.text-title-advantages }}
            
            

{{ block.settings.textarea-advantages }}

          

        {% endif %}
      {% endfor %}
      
      
      

        
      

    

  

{% schema %}
  {
    "name": "t:sections.main-register.name",
    "settings": [
      {
        "type": "header",
        "content": "Custom text",
        "info": "If you need a back to line, you can use this balise 
"
      },
      {
        "type": "text",
        "id": "text-login-back-website",
        "label": "Back to website title",
        "default": "Retour au site"
      },
      {
        "type": "text",
        "id": "text-login-title",
        "label": "Login title",
        "default": "Rejoindre le club"
      },
      {
        "type": "text",
        "id": "text-register-information-title",
        "label": "Information title",
        "default": "Parrainage"
      },
      {
        "type": "text",
        "id": "text-register-information-message",
        "label": "Information message",
        "default": "Pour adhérer au Club, vous devez obligatoirement avoir une personne qui vous a recommandé."
      },
      {
        "type": "header",
        "content": "Footer button"
      },
      {
        "type": "text",
        "id": "text-register-button-back",
        "label": "Button back",
        "default": "Retour"
      },
      {
        "type": "text",
        "id": "text-register-button-confirm",
        "label": "Button confirm",
        "default": "Continuer"
      },
      {
        "type": "color_scheme",
        "id": "form_color_scheme",
        "label": "form colors",
        "default": "scheme-2432f7e6-8bee-4498-ba7d-8e410826ace2"
      },
      {
        "type": "color_scheme",
        "id": "advantages_color_scheme",
        "label": "advantages colors",
        "default": "scheme-3"
      }
    ],
    "blocks": [
      {
        "name": "Advantages",
        "type": "advantages",
        "settings": [
          {
            "type": "text",
            "id": "text-title-advantages",
            "label": "Advantages Title"
          },
          {
            "type": "textarea",
            "id": "textarea-advantages",
            "label": "Advantages Text"
          }
        ]
      }
    ]
  }
{% endschema %}

I hope this will serve your porposes. If you have any qoustion. ask me. I will reply you.

Thanks.

Thanks but why not using :

{%- if form.posted_successfully? -%}
{%- endif -%}

your solution :

because if i need to use custom redirection en other form with {% if customer %} it will not work, why form.posted_successfully doesn’t work ?

thanks.

Hello @EnzoLC ,

1. I did research about it in Shopify documentation but did not find anything about it. Anyway, I am sharing with you my thoughts, on what could happening behind the scenes.

"When the form for login or registration or any kind of form should redirect to other pages, after submitting them the page does not cache that the form is submitted, so after the page refresh, form submitting cannot veryfying by liquid objects.

When a form is a contact form or any other form that should not redirect the user to a different page, these are caches the data that the form is submitted. So after the page refreshes, we can check it via liquid objects."

It is my thoughts, that could be wrong.

2. If you want to take action after the form submit for other forms. Use this method first,

{%- if form.posted_successfully? -%}
{%- endif -%}

if this does not work, then try this differently. Like the register form.

If You got your solutions, mark it as an accepted solution. If you have any questions again. Ask me about that. It is my pleasure to help you.

Thank you.

also having this issue on the ‘create-customer’ form. {%- if form.posted_successfully? -%} doesn’t seem to work for the create-customer form, and the {%- if customer -%} doesn’t work since this form seems to have a default behavior I can’t override while maintaining the Shopify form validation.