Redirect via Webhook After Form Submission

Hello all! At one point, using a combination of custom code and Make webhooks, we were able to redirect to unique links via form submission. I’m trying to do so again, but am running into a lot of trouble. Here’s my current workflow:

Pre-requisite: add the following code into Settings > Custom Code > Code Inside Header:

<script>
document.addEventListener("DOMContentLoaded", function() {
$(document).ajaxSuccess(function( event, xhr, settings ) {
if(xhr.responseText) {
const json = JSON.parse(xhr.responseText);
if(json && json.redirect) {
window.location.href = json.redirect;
}
}
});
});
</script>
  1. User submits a form. Softr form settings should not be “Open Page.”

  2. On submission, Softr sends the info to a Make webhook, like so:
    Screen Shot 2022-10-13 at 10.27.54 AM

  3. Make receives the webhook.

  4. Make then issues a 200 webhook response, with a redirect to a given site, like so:
    Screen Shot 2022-10-13 at 10.26.24 AM

  5. What’s then supposed to happen is that the script added to the custom header above watches for the operation’s success, and then redirects to the website listed in Make. That’s not happening, though.

I’ve built this workflow before, but for some reason now I can’t get it to work. Can anyone spot something I’m missing or an error I’m making, or can anyone confirm that the above code is no longer functional with the React update?

@adalys are you using a new form block ?

Hi @artur ! Yes, I am.

@adalys we transitioned form blocks to react and few things changed. We will be sharing a code sample on how to handle it in the next few days

Hi @artur Any update on this? I am in the exact same situation too.

Thanks!

@Nickshas and @adalys can you try the code below:

<script>
    window.addEventListener('submit-form-success-form1', (e) => {
        const response = e.detail.response || {};
        const data = response.data;
        if (data && data.redirect) {
            window.location.href = data.redirect;
        }
    });
</script>

This code will be working with new form blocks

1 Like

Thank you! This has worked for me!

Hi @artur, @adalys and @Nickshas

The new script finally works for me :pray: Thanks a lot

I would like to share a tip that took me a while to find : don’t forget to use “https://…” in the redirect URL :innocent: