getCurrentItem? Help

Context: I am trying to create a membership site with a registration page. The visitor is asked to sign up and then sent to fill our their profile and additional info. I used the how to create member profile pages article for my log in/profile page so most of my site code comes from that.
Now I’d like to either hide a couple ‘register’ buttons on the home page when members who have completed the form are logged in, or to disable the buttons for said members. I keep getting errors when I attempt to plug in code. My thinking was to use something along the lines of an onReady function with getCurrentItem to check a field (e.g. ‘registered’), and if the field was ‘x’ then the button would hide. Any help would be greatly appreciated as I’ve spent way too much time trying to figure this out.

Hi Ryan,

Welcome to the Wix Code forums.

What have you tried so far and what errors are you getting?

To show or hide a field based on a user login, you might do something like this:

$w.onReady(function () {
 let user = wixUsers.currentUser;
 if (!user.loggedIn){
   $w(#button1).show();  // show when user logged in
   $w(#button2).hide();  // show when user not logged in
 }
});

This is a REALLY simple example. All I’m doing is hiding or showing a couple buttons based on a user being logged in.

i would suggest reading about wix-users which will give you all you need to control user logins and page access.

Good luck,

Yisrael

panisssss

am getting an error when i insert my button,

$w(#button1113).show();

@paiysurv
Put it as this…
$w(“#myElement”).show();

Plus button 1113, now that is a lot of buttons, how do you know where all those 1000 plus buttons are on your site?!

Always a much better idea to change the elements id name so that it matches what it is actually for and it makes it much easier to work with in code etc.

@givemeawhisky Thank you. It worked. I renamed the button to avoid duplication.