Button not working with wixlocation.to

Hi all, My button won’t redirect to the location in my account section.

I have been trying for the past 24 hours and I just can’t find a way. I am not sure if the button is functioning at all. If you want to take a look its www.inshapeithcraig.co.uk

upon login go to profile and the button will be there, “createProfileButton”

please help its driving me crazy.

thank you, code is posted below. one for profile page and other for sign in page.

this is the code i have for the my profile page (I followed a video)

import wixData from ‘wix-data’;

$w.onReady( function () {

$w(“#updateProfile”).onReady( () => {

let isEmpty = $w(“#updateProfile”).getCurrentItem();

let theName = $w(“#firstName”).value;

if ( isEmpty === null ) {

  $w("#createProfileButton").show(); 

  $w("#updateProfileButton").hide(); 

  $w("#profileArea").collapse(); 

  $w("#welcomeUser").text = `Welcome New User. Please create a profile!`; 

}  **else**  { 

  $w("#updateProfileButton").show(); 

  $w("#welcomeUser").text = `Welcome ${theName}`; 

  $w("#profileArea").expand(); 

} 

} );

$w(“#updateProfile”).onAfterSave( () => {

let theName = $w(“#firstName”).value;

$w("#welcomeUser").text = "Update Completed!"; 

const millisecondsToDelay = 2500;

setTimeout(() => {

$w(“#welcomeUser”).text = Welcome ${theName};

}, millisecondsToDelay);

});

});

this is the code for the sign up page…

import wixUsers from ‘wix-users’;

import wixData from ‘wix-data’;

import wixLocation from ‘wix-location’;

$w.onReady( function () {

let user = wixUsers.currentUser;

let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”

let isLoggedIn = user.loggedIn; // true

user.getEmail()

.then( (email) => { 

let userEmail = email;

$w("#emailText").value = userEmail; 

let referralCode = userId.split(“-”)[4];

} );

$w(“#createProfileButton”).onClick( () => {

let toInsert = {

“firstName”: $w(“#firstName”).value,

“lastName”: $w(“#lastName”).value,

“emailAddress”: $w(“#emailText”).value,

};

wixData.insert(“Members”, toInsert)

.then( () => {

wixLocation.to("/account/my-profile"); 

} )

. catch ( (err) => {

let errorMsg = err;

$w("#error").show(); 

} );

});

});

Hey Craig,

I am not sure if the button is functioning at all.
The Create Profile button isn’t connected to anything - so it seems that this button in fact is not functioning. You probably should connect it to “Submit”:


I hope this helps,

Yisrael

Hi Yisrael and thanks for the reply, when I add the submit my button blanks out on the live site. The create profile button is supposed to redirect me to the update profile page, there is then a button there which is connected to the submit function.

This button is not connected to Submit, and it has no action associated with it. So, clicking on this button does just what it was told to do - nothing .

1 Like

haha I hear you but I took submit off as on the live site it greys the button out. I added submit back if you want to see and see if you can make sense of it?

the action is specified in the code? $w(“#createProfileButton”).onClick( () => {

let toInsert = {

“firstName”: $w(“#firstName”).value,

I don’t see that code on the page. You’ll need to provide some sort of action to that button. You can take a look at the article How to Create Custom Member Profile Pages with Wix Code for ideas on how to do this.

I did create the function which is $w.onReady( function () {

So it is connected that way but it just does not work so i am missing something some where