Change redirect after form submission

Répondu

10 Commentaires

  • Pedro Rodrigues
    Community Moderator

    Hi Kevin Halbrook, one way to do it is to add the following Javascript to your document_head.hbs file in your Guide theme.

    <!-- Redirect user after form submission -->  
    <script>
    if (document.referrer.match('/requests/new')) {
      window.location.href = 'URL';
    }
    </script>

    All you have to do is replace "URL" with the real URL you want to redirect your users to.

    Hope this helps!

    1
  • Kevin Halbrook

    That is exactly what I needed.  Thank you so much, Pedro.

    0
  • Pedro Rodrigues
    Community Moderator

    You're welcome, I'm happy to help!

    0
  • Amy Giella

    Hi Pedro,

    I think this is exactly what I need, but when I added the code to document_head.hbs, it now redirects to the correct page when I select a form (before having the chance to enter any information). Is there a way for the user to select the form, fill it out, submit the form, then redirect to a specific page?

    Thanks!

    1
  • Pedro Rodrigues
    Community Moderator

    Hi Amy Giella, thank you for that heads-up, the code should indeed prevent that situation! I just tried this in my account and it worked without any issues:

    <script>
    if (document.referrer.match('/requests/new') && (window.location.href.indexOf("/requests/new?ticket_form_id=") === -1)) { 
      window.location.href = 'URL';
    }
    </script>

    Cheers!

    1
  • Amy Giella

    Hi Pedro,

    It redirects after the user submits the form, which is fantastic! 

    I am noticing, however, that it redirects every time the form is submitted, even if required fields are left blank. So instead of seeing the notices that the form cannot be submitted when XYZ field is blank, I am redirected automatically and don't realize that the form wasn't actually submitted. I checked the Support agent workspace and confirmed that tickets are only created when those required fields are filled in. Is there a way to redirect only after a successful submission?

    0
  • Nicole

    Pedro Rodrigues Is there any way to do this for a single form when there are multiple? 

    Editing to add Ifra Saqlain...would you happen to know how to adjust? 

    I did try this code on the document_head.hbs page: 

    <script>
    if (document.referrer.match('/requests/new') && (window.location.href.indexOf("/requests/new?ticket_form_id=[form id number]") === -1)) {
      window.location.href = 'https://zendeskformlink';
    }
    </script>
    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Nicole, I tried for single form but couldn't get it.

    0
  • Nicole

    Ifra Saqlain thank you so very much for trying! I didn't have luck either with trying to limit it to a single form. 

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    I have been doing it for an hour, applying ideas but couldn't get it done perfectly.

    0

Vous devez vous connecter pour laisser un commentaire.

Réalisé par Zendesk