Help with page redirect!

@benibrodi ITS WORKING!!!. I published the website and it worked. !!! Thank you! You are an awesome human being.

@salman_badshah

Great! :smiley:

@jonatandor35 Thank you. It’s working. I had to publish the website and it was working fine.

@salman_badshah

So you are following this tutorial here.
https://support.wix.com/en/article/corvid-tutorial-creating-a-custom-registration-form-with-code

Well first thing to note is that Wix Users doesn’t work in preview mode, to test it properly you need to be using your live published site only.

The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.
https://www.wix.com/corvid/reference/wix-users.html

As for your code.
Your submit click underneath your pages onReady function should be
$w(‘#submit’).onClick( () => {
Which includes the onClick event handler in the code itself.

Whereas you have it setup as this
$w(’ #submit ').onClick( function () {
Which is setup as through the event handler in the properties panel for the element and it should be setup something like this instead with an export function.
export function profilebutton_onclick(event) {
wixLocation.to(/Members/${wixUsers.currentUser.id});

Then as J. D. first tells you and provides you with the link for you to see the code in the API reference itself, which then Be shows you in code, it should have the .then results code underneath your register’s contact info.
}
} )
.then( (result) => {
let resultStatus = result.status;
} );
And into that you can add your wix location call to take you to your other page, however you need to make sure that you close your open lightbox first.

.then( (result) => {
let resultStatus = result.status;
wixWindow.lightbox.close();
wixLocation.to(“/yourpageURLhere”); //Change the URL ending to whatever page you want to send the user to after they log in.

So your code should be something like this, however you would need to just check for matching pairs of curly brackets and parentheses as I’ve just stuck it together quickly to show you.

import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;

$w.onReady(function () {
$w(‘#submit’).onClick( () => {
let emails = [];
let labels = [];

emails.push($w('#email').value); 

const age = $w('#age').value; 

// calculate the proper age label 
if (age < 18) { 
  labels.push("Below 18"); 
} else if (age < 25) { 
  labels.push("18 - 24"); 
} else if (age < 36) { 
  labels.push("25 - 35"); 
} else { 
  labels.push("Above 35"); 
} 

// register as member using form data 
wixUsers.register($w('#email').value, $w('#password').value, { 
  "contactInfo": { 
  "firstName": $w('#firstName').value, 
  "lastName": $w('#lastName').value, 
  "emails": emails, 
  "labels": labels, 
  "age": Number($w('#age').value) 
    } 

} )
.then( (result) => {
let resultStatus = result.status;
wixWindow.lightbox.close();
wixLocation.to(“/home-1”); //Change the URL ending to whatever page you want to send the user to after they log in.
} );
} );

});

There are different ways you can do it as well, this is my own code for it.

import wixUsers from ‘wix-users’;
import wixWindow from ‘wix-window’;
import wixLocation from ‘wix-location’;

$w.onReady(function () {

$w("#registerButton").onClick( (event) => { 

let email = $w(“#email”).value;
let password = $w(“#password”).value;
let first = $w(“#firstName”).value;
let last = $w(“#lastName”).value;

wixUsers.register(email, password, {
contactInfo: {
“firstName”: $w(‘#firstName’).value,
“lastName”: $w(‘#lastName’).value,
}
} )
.then( (result) => {
let resultStatus = result.status;
wixWindow.lightbox.close();
wixLocation.to(“/sign-in-status”); //Change the URL ending to whatever page you want to send the user to after they log in.
} );
} );

});

NOTE: you can also take out the wixLocation.to line and add wixWindow.openLightbox(“Login”);
at end of code if you don’t want the lightbox to close and then to open the login lightbox if you don’t already have that option setup on your signup lightbox.