Hi, I am new to coding. I would like to send users to the specific page after signing up. I wrote some code based on some online tutorials, but it still doesn’t work. Users still stay on the same page after they signing up. Could someone help me solve this problem? Thank you very much!
Here is my code
import wixUsers from ‘wix-users’ ;
import wixWindow from ‘wix-window’ ;
import wixLocation from ‘wix-location’ ;
$w . onReady ( function () {
$w ( ‘#next’ ). onClick (() => {
**if** ( $w ( "#firstName" ). valid && $w ( "#lastName" ). valid && $w ( "#email" ). valid && $w ( "#password" ). valid ) {
**let** emails = [];
emails . push ( $w ( '#email' ). value );
wixUsers . register ( $w ( '#email' ). value , $w ( '#password' ). value , {
contactInfo : {
"firstName" : $w ( '#firstName' ). value ,
"lastName" : $w ( '#lastName' ). value ,
"emails" : emails ,
"university" : $w ( '#findYourSchool' ). value || $w ( '#findYourSchool2' ). value || $w ( "#inputYourUniversity" ). value || $w ( '#Company' ). value ,
"CurrentLearningStage" : $w ( '#CurrentLearningStage' ). value ,
"EnrollmentYear" : $w ( '#EnrollmentYear' ). value ,
}
})
. then ( ( result ) => {
**let** resultStatus = result . status ;
wixWindow . lightbox . close ();
wixLocation . to ( "/spoc" ); //Change the URL ending to whatever page you want to send the user to after they log in.
} )
} **else** {
console . log ( "Some inputs are invalid" );
$w ( '#errorMessage2' ). show ();
}
});
})
Hello, I’m afraid I don’t have a direct answer as my code is very similar but works as expected. I can speculate a couple things if that helps at all.
First, I have had some issues with using the URL slug shortcut code in my code in the past. I now just use “https://www.yoursitename/spoc” to be sure instead of the “/spoc”.
Second, I wonder if having the wixWindow . lightbox . close (); command before the wixLocation.to command could be part of it. I don’t have the lightbox close command at all and it seems to work fine.
Hi there …
The problem with your code is that you’re closing the lightbox before redirecting the users, which means the code never make it to the redirection command as it gets terminated by the lightbox close command.
Another thing, when loggin in, signed up, or logged out, you should always refresh the website, therefore, it’s recommended to use your site’s base URL, or the full URL of the page you want to redirect your visitors to.
this still doesn’t work even though I use the full URL and delete wixWindow . lightbox . close ();
$w ( ‘#next’ ). onClick (() => {
if ( $w ( "#firstName" ). valid && $w ( "#lastName" ). valid && $w ( "#email" ). valid && $w ( "#password" ). valid ) {
let emails = [];
emails . push ( $w ( '#email' ). value );
wixUsers . register ( $w ( '#email' ). value , $w ( '#password' ). value , {
contactInfo : {
"firstName" : $w ( '#firstName' ). value ,
"lastName" : $w ( '#lastName' ). value ,
"emails" : emails ,
"university" : $w ( '#findYourSchool' ). value || $w ( '#findYourSchool2' ). value || $w ( "#inputYourUniversity" ). value || $w ( '#Company' ). value ,
"CurrentLearningStage" : $w ( '#CurrentLearningStage' ). value ,
"EnrollmentYear" : $w ( '#EnrollmentYear' ). value ,
}
})
. then ( (result) => {
wixLocation . to ( "https://www.touchedu.io/spoc" );
} )
} **else** {
console . log ( "Some inputs are invalid" );
$w ( '#errorMessage2' ). show ();
}
});
one thing is strange.
I am not sure why “result” appears light blue. Does it mean that it cannot function ?
