Complete guide: Redirect users to the page they were before signing up/signing in + onboarding use case

The guide will be cut in 3 parts: Sign up and Sign in redirect / Reset password Redirect / Redirect after Sign up + Onboarding flow

1) Redirect after Sign up or Sign In

First of all the event listener for sign up/sign in success is the following one

window.addEventListener('submit-form-success-signup_or_signin_formID', () => {

Exactly the same as the classic form submit event listeners!

Small explanation for what is following: you will notice that the code is a little more complex than a classic redirect (see part 2)
With Sign up and Sign in forms, we have a little problem: Softr has a mandatory pre-made redirect (see screenshot). And we need to override it, hence a cookie solution suggested and refactored by @artur

Here is what you need to insert in the header code at APP LEVEL. Note that ‘useraccounts1’ is both used as an ID for the sign up and for the sign in forms ⇒ I gave them the same ID.

<script>
  window.addEventListener('submit-form-success-useraccounts1', () => {
    const currentPageUrl = window.location.href;

    _setCookie('signInUpRedirectionUrl', encodeURIComponent(currentPageUrl), 1);

    setTimeout(() => {
      window.history.go(-1);
    }, 100);

    function _setCookie(name, value, days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "expires=" + date.toUTCString();
        document.cookie = name + "=" + value + ";" + expires + ";path=/;" + 'SameSite=Lax; Secure';
    }
  });
</script> 

2) Reset password redirect

There is a mandatory redirect, right now, after password reset which is your homepage.

In the header code, at APP LEVEL, insert this code to decide of another redirection.

Change useraccounts3 by your actual reset password form ID

<script>
  window.addEventListener('submit-form-success-useraccounts3', () => {
    const currentPageUrl = window.location.href;

    _setCookie('signInUpRedirectionUrl', encodeURIComponent(currentPageUrl), 1);

    setTimeout(() => {
      window.location.href = 'https://yourdomain/signin'; // signin page should be logic as redirection
    }, 100);

    function _setCookie(name, value, days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "expires=" + date.toUTCString();
        document.cookie = name + "=" + value + ";" + expires + ";path=/;" + 'SameSite=Lax; Secure';
    }
  });
</script>

3) Redirect after Sign up + Onboarding flow

This will be useful for all of you that have an onboarding flow after a sign up.

So let’s say that after sign up you redirect (with the native Softr settings, no need for code) the user to a page where there is a form to fill a first batch of additional information. After completing this form the users are finally redirected, to a last onboarding page, again with a form to complete to fill a last batch of additional information.
So our use case would be a 2 steps onboarding.

After this last form submission, the idea would be to redirect them to the page they were before the whole onboarding and sign up process.

Here is the code to do so. To be inserted in the footer code at page level (page where is the last form)
You can adapt it by changing history.Back(-3) by -2 or -4 or whatever fits your needs (meaning the number of onboarding pages).
Change ‘formid’ by your actual form ID

<script>
document.addEventListener('DOMContentLoaded', () => {
  window.addEventListener('submit-form-success-form1', () => {
    window.history.go(-3);
  });
});
</script>

You can add a little delay before a go back (here: 1,5 sec, change it by playing with‘1500’)

<script>
  document.addEventListener('DOMContentLoaded', () => {
    window.addEventListener('submit-form-success-form1', () => {
      setTimeout(() => {
        window.history.go(-3);
      }, 1500);
    });
  });
</script>

Thank you all

4 Likes

what about email code sign in?
Thanks!

Hello @matthieu_chateau thanks for this. Ias thsi still working? I couldnt make it work on my end

thanks

Hi,
Which code/use case are you referring to?

Redirect after Sign up or Sign In.

The user click to fill a form which is only allowed for sign in users. I would like that after sign up/in it goes to the form

for this case: Redirect after Sign up + Onboarding flow : if possible, i would like the user to complete profile before going to the from

Yep, they are all working.

Can you copy paste the code you are using? (Use the </> option in the text editor to enter code)

this code for the simple redirect:

<script>
  window.addEventListener('submit-form-success-useraccounts1', () => {
    const currentPageUrl = window.location.href;

    _setCookie('signInUpRedirectionUrl', encodeURIComponent(currentPageUrl), 1);

    setTimeout(() => {
      window.history.go(-1);
    }, 100);

    function _setCookie(name, value, days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "expires=" + date.toUTCString();
        document.cookie = name + "=" + value + ";" + expires + ";path=/;" + 'SameSite=Lax; Secure';
    }
  });
</script> ```


I have also named the sign up and sign in as "useraccounts1"

Hey @matthieu_chateau it worked now. It only works in the live version right? I was trying to make it work with the preview version.

I will try the option with the onboarding now

Ah yes!
It works only in the live version. Yes.

1 Like

Thanks a lot @matthieu_chateau I will let you know if i can do the onboarding version. :slight_smile:

Do I need to delete the code 1 on app header level to make the code 3 (onborading) to work?

Actually it also works in the preview mode. But you need to test it right. You start in a page then replace the url in the preview mode. But anyway, yes they are properly working.

Hi @matthieu_chateau , it seems this does not work for email code log in block?@@
could you please help?

Hi,
Unfortunately, none of these codes work for the email code based sign in. This should be linked to the specific two steps needed for this type of sign in or just because there are not event listenners linked to this type of signin block.

1 Like

Hi Matthieu –

Is there a way to create a Magic Link to take a user to the onboarding page?

My users are synced with SmartSuite and not created through sign ups on Softr.

I want to invite them by a magic link that takes them to the onboarding page (then to the home page once they’ve completed onboarding info).

Thank you!

Hi Kristin,

This is possible yes.

For Airtable: If you have a magic link field (here it would be named “Magic link”) then you can create this formula field to take the user to a specific page (not the homepage).

{Magic link}&'&next-page=/onboarding-page'

For SmartSuite:
CONCAT([Magic link], "&next-page=/onboarding-page")

1 Like

Thank you!

Thank you for the detailed descriptions @matthieu_chateau. I’m looking to use just the simple redirect and wondered if this still works since the softr redirect is handled now in Page Rules. The code here is not currently working for me: It continues to redirect as outlined in page rules.

Hi,

Yes, it does work without any problem.

The script needs to be added in the custom code, app settings

Thanks Matthieu yes I have copy pasted the script into the app settings custom code section in the header and updated the form name to the name of my form block “sign-in-desk-modal”. My sign in form is a modal form could that be the problem?

Mmmmm no, the fact that your sign in block is inside a modal should not be a problem as it works in this case too.

It may be a conflict with another code or your browser settings impeach some cookies to work (as the script relies on a cookie to work).