Redirect after successfully submitting form

Answered

5 Comments

  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Hi Amy Giella,

    I tested the following modification on Copenhagen 2.18.0

    <script>
    if (document.referrer.match('/requests/new') && (window.location.href.indexOf("return_to=%2Fhc%2Frequests") !== -1)) { 
      window.location.href = 'URL';
    }
    </script>

    Basically I noticed that the theme has a default redirect to guide home with the query param return_to=%2Fhc%2Frequests, so you can look out for it and redirect the end user.

    Hope that helps.

    0
  • Amy Giella

    Hi Ahmed Zaid,

    Thank you for taking a look at this! I used this in the document.head.hbs after replacing "URL" with the custom page's URL. It does make the user fill in all the required fields before submitting the form, but instead of taking me to the custom page, I am taken back to the main home page. Am I maybe adding the code to the wrong place? I'm not sure what else to try.

    0
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Hi Amy,

    It works for me whether I add it to the top of the header template or directly in the script.js file. Can you try adding the url as

    /hc/{{help_center.locale}}/p/your_page_title

    Replace only your_page_title

    0
  • Brittany Loy

    Great, this works for me however it bypasses the required fields. What else can I do to ensure when submitting it won't bypass the required fields so the user must fill out the required fields first and then submit the form, which still redirects?

    0
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Hi Brittany Loy,

    I am not sure how it bypasses the required fields. Can you share more details about the exact steps you took?

    0

Please sign in to leave a comment.

Powered by Zendesk