Important redirect functionality missing?

I’m using wix studio and am not a coder. Used wix for years, but always had issues with the members area, so I’ve steered clear. I really need it now, so trying again. I need to implement a members only survey, but with the redirect to the first page of a multi page Wix form triggered when a new member has subscribed and validated? Any ideas or Velo workarounds?

Product:
[Which editor or feature is your question most relevant to? e.g. Wix Editor, Wix Studio Editor.]

What are you trying to achieve:
[Explain the details of what you are trying to achieve. The more details you provide, the easier it is to understand what you need.]

What have you already tried:
[Share resources, forum topics, articles, or tutorials you’ve already used to try and answer your question.]

Additional information:
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]

So basically you need this redirect to occur on the member’s first login? Or rather, until that member has filled a certain form?
This is not too complex, shouldn’t intimidate you much :slight_smile:

I get that you’re trying to redirect to the first page of a form with multiple pages, but are you trying to exclude the other pages of that form or something? Need more details to better understand.

What’s the issue with simply making that page where the form is on a Members Only page via the page settings?

2 Likes

Thanks. No, the form just moves from page to page as people progress. It’s so that people don’t have the additional annoying step of having to press the (take the survey) button for a second time.

Thanks Dean. It’s actually more complex. So, if someone is already a member and is logged in, then the ‘Take survey’ button that is in the header needs to work as normal - just going to the survey page. However, if someone is not logged in or is not a member, it needs to take them to the sign in / sign up Lightbox, and upon sign in, take them to the ‘Take Survey’ page, or on validation of email, it needs to redirect them to the ‘take survey’ page. Hope that helps clarify. I appreciate your answers and help.

In that case, you don’t need to write any code at all. The simple solution provided by @codequeen should work flawlessly.

It is. Sorry, should have said that. But its the redirect after login or sign up that I need

Simple…

A. Normal button in the header, linking to the survey page
B. The survey page permissions are locked to member only

Now the login prompt is handled if a non-logged-in member heads over to the form

C. Utilize the onLogin event to redirect the member to the proper page, be it on any login or dependent on some info

Just the onLogin trigger

Hi all. Thanks for your help. In the end, Chat GPT came to the rescue and the solution worked. Just posting here for background…

Me… Sorry, I am getting very confused. The problem is that after someone submits the registration form, they then have to respond to a validation email prior to their being logged onto the site. It is then that I would like the redirect to the /NHSSurvey page

Chat GPT. Got it! The key challenge here is handling the email validation process in Wix, which introduces a delay before the user is fully registered and logged in. To solve this, we need to set up the following flow:

Chat GPT answered, but it was still confusing to me (If anyone wants the answer - happy to share)

Me. Please could you explain exactly where I enter the above code?


Chat GPT. Absolutely! Here’s a detailed explanation of where to place each piece of the code in Wix Studio, step by step.


Code Placement Overview

Wix Studio’s code is split into Page Code, Site Code, and Backend Code. Each has its specific role:

  • Page Code: Code specific to an individual page.
  • Site Code: Global code that applies across your entire site (e.g., redirects or user authentication checks).
  • Backend Code: Secure server-side code for sensitive operations.

Now, here’s where you place the code:


1. Registration Form Logic (Step 2 Code)

This code handles the user’s registration and stores the redirect path for after validation.

Where to Place:

  • Go to the page where your registration form is located.
  • Open the Code Panel at the bottom of the page in Wix Studio.
  • Paste the Registration Form Code into the Page Code section.

Example Code for the Registration Page:

import { session } from 'wix-storage';
import wixUsers from 'wix-users';

$w.onReady(function () {
    $w("#signUpButton").onClick(async () => {
        const email = $w("#emailInput").value;
        const password = $w("#passwordInput").value;

        try {
            // Register the user
            await wixUsers.register(email, password);

            // Store the redirect path for later use
            session.setItem("redirectAfterValidation", "/NHSSurvey");

            // Show a message to check their email
            $w("#successMessage").text = "Check your email to verify your account.";
            $w("#successMessage").show();
        } catch (error) {
            console.error("Registration error:", error);
            $w("#errorMessage").text = error.message;
            $w("#errorMessage").show();
        }
    });
});

2. Post-Validation Redirect (Step 3 Code)

This code handles the user’s redirection after they validate their email and log in.

Where to Place:

  • Go to the Site Code section:
    1. Open the left-hand panel in Wix Studio.
    2. Under “Code Files,” locate Site Code (masterPage.js).
    3. Paste the Post-Validation Redirect Code into this file.

Example Code for Site Code (masterPage.js):

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import { session } from 'wix-storage';

$w.onReady(function () {
    const user = wixUsers.currentUser;

    // Check if the user just logged in and has a stored redirect path
    if (user.loggedIn) {
        const redirectPath = session.getItem("redirectAfterValidation");

        if (redirectPath) {
            // Clear the stored redirect to avoid re-triggering
            session.removeItem("redirectAfterValidation");

            // Redirect the user to the stored path
            wixLocation.to(redirectPath);
        }
    }
});

3. Enable Email Verification

This isn’t code but a setting in your Wix dashboard. To enable email verification:

  1. Go to your Wix Editor.
  2. Click Settings > Roles & Permissions > Member Signup.
  3. Turn on Require Email Verification.

How the Code Works

  1. Registration Page Code:

    • Registers the user and stores /NHSSurvey in session storage for later redirection.
    • Informs the user to check their email for a validation link.
  2. Site Code (masterPage.js):

    • Checks if a logged-in user has a pending redirect after email validation.
    • Redirects the user to /NHSSurvey if the redirect path was stored.
  3. Email Verification Setting:

    • Ensures the user cannot log in until they validate their email.

Testing the Implementation

  1. Test Registration:

    • Fill out the registration form and ensure the success message appears.
    • Check the session storage using the browser’s developer tools to confirm /NHSSurvey is stored.
  2. Test Email Validation:

    • Open the email validation link.
    • After logging in, ensure the user is redirected to /NHSSurvey.

Let me know if you need more guidance or encounter any issues!


That was all chat GPT, though I am sure ‘it’ was using answers some of you might already have given. Just like magic… Anway - the solution worked. Thanks.

A. WixUsers is long long deprecated and might not work for long
B. String the redirect path in session is rather useless from what I can tell
C. This will only work if the user registers and validates the email at the same time. If they head for validation in a different browser or at a later time, this will not redirect them, It;s overcomplicating the pretty simple design that you’ve been describing so far

You may want to reconsider your entire approach. It will most likely produce bad user experience.

For many reasons but I will focus on just one…

A person can stop filling out the form and wants to continue where they left off because …… like you said, they won’t want to start over again……

How do they get back to where they stopped?
How does the website know they started but did not finish?

@codequeen & Dean, Pratham & 911Freelance

Thanks for your responses. www.LetsFixTheNHS.help is the website in question. Its built with my limited technical ability to deliver a beta site which is more of a concept document to get the platform idea across, so we can raise the funds to launch properly. When we do, the idea is we will have full stack developer internally for a more structured and planned build, but in the interim, we will make the wix site sing and hopefully, do a better job than the current version. Do have a look - and when we are funded in the next few weeks, I will reach out. Many thanks. Steve