Help with page redirect!

Hey there,
I don’t know code. What i want is for my users to be redirected to a Thank you page or home page. wixLocation doesn’t seem to work.

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

$w.onReady( function () {
$w(‘#submit’).onClick( function () {

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)

        } 
    }); 

    wixLocation.to.to("/home");  

}); 

});

wixLocation.to not wixLocation.to.to

Still not working :frowning:

@salman_badshah You’re timing is wrong.
Since wixUsers.register() is a promise, you should put everything you want to happen after successful registration in a .then() part. see:
https://www.wix.com/corvid/reference/wix-users.html#register

2 Likes

@jonatandor35 Hey, Thank you for replying. I Should confess I am really bad at code. So this is what I did and it’s giving me a parsing error (Don’t know what this means).

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

$w.onReady( function () {
$w(‘#submit’).onClick( function () {

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,
.then( () => {
wixLocation.to(“/home”); })
{
“contactInfo”: {
“firstName”: $w(‘#firstName’).value,
“lastName”: $w(‘#lastName’).value,
“emails”: emails,
“labels”: labels,
“age”: Number($w(‘#age’).value)

        } 
    }); 

//Change the URL ending to whatever page you want to send the user to after they log in

}); 

});

@salman_badshah
Ay ay ay… I see something. A bracket “)” is missing.

Your code:

 wixUsers.register($w('#email').value, $w('#password').value,             .then( () => { 
 ....
 ...

And now have a look at the Corvid-Example:

wixUsers.register(email, password)
  .then( (result) => {
    let status = result.status; // "Active"
    let user = result.user;
  } );

Can you find it :wink:

1 Like

@benibrodi Still not Working :frowning:

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

$w.onReady( function () {
$w(‘#submit’).onClick( function () {

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(() => { 

            wixLocation.to("/home"); 
        }) 

}); 

});

@salman_badshah

Hm it looks now correct, like it should:

wixUsers.register(email, password, {
    contactInfo: {
        "firstName": firstName,
        "lastName": lastName,
        "phone": phone,
        "nickname": nickname
    }
  } )
  .then( (result) => {
    let resultStatus = result.status;
  } );
 

Can you please show the hole Error-Message (e.g screenshot).

@benibrodi There is no error showing. When I click on the Sign Up button, it does not go to home page. It’s just on the same page.

@salman_badshah

Well, then must be the issue here:

                 wixLocation.to("/home"); 

The question is, is “home” the correct Page-Name?
Go and check your Page-Names and have a look at the Tab: SEO (Google)

And try this:

                 wixLocation.to("/"); 

@benibrodi

The Page title? or the URL?

@salman_badshah it’s “/home-1”

@salman_badshah

Did you tried this?

 wixLocation.to("/"); 

@jonatandor35 Still not working.

@benibrodi I even tried just this

wixLocation.to("/");

It’s still not working

But the register works ?

Take this code and see what the console log say:


  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 => {
  console.log(result.status);
  wixLocation.to("/home");
  })      
}); 

PS: Dont forget to delet all this extra Hastags-Variable here that Wix-Forum do. Just stupid that happen even in the Code-Section. Please Fix Wix-Team

Yes, Yes wierdly. It works. But is stuck on the same page.

@salman_badshah

Well I don’t know how to help you more.
I can’t see from here what would be next probably “issue”-factor.