How do I use UserInfo?

Ok, so here is what I am trying to do. I have created a site where (logged-in)members submit information through a form and I need to show that information on a “Past Submissions” page. I figured the best way to do something like this was to:

  1. have a collection where the form submissions go (done)
  2. since users are logged in, I was hoping to be able to collect their emails, or something that uniquely identifies them
  3. Upon collecting their emails, I was hoping to add “email” as a column to the form submission data, and put their email there with the rest of it.
  4. then, I would’ve created a dynamic page(the submission page) for users, where I display certain columns from the form submissions
  5. Then, I use a filter feature by rows(not sure if this one would work), and if the user’s login email matches the email in that row, only those rows show up, meaning that they only see the rows attached to their emails (also, the email column wouldn’t be displayed here)

So I’ve been looking through a few resources on Corvid, and am unsure on how exactly to do this, or produce a similar result with a different process. Keep in mind I am new to Javascript and more familiar with Java, so please be detailed in how to carry things out in terms of syntax.

I was a little bit confused with how to carry out a few of the steps above, however. For step 2, I used this article , which didn’t work for me. This was my code:
(button2 is the submit button for the form. I’ve ensured all the names for the collections are correct, but when I view the collection, nothing changes in the email column I created, and I don’t receive any sort of error that I’ve seen)

import wixUsers from “wix-users” ;
import wixData from ‘wix-data’ ;

let user = wixUsers.currentUser;
let userEmail;
user.getEmail()
.then( (email) => {
userEmail = email;
} );

export function button2_mouseIn(event) {
let toInsert = {
“email” : userEmail
};

wixData.insert( “multiStepRegistrationForm3” , toInsert)
.then( (results) => {
let item = results; //see item below
} )
. catch ( (err) => {
let errorMsg = err;
} );
}

Later, I found this link which should’ve also been able to help me. It provided this code to receive member data:
wixData.query( “Members/PrivateMembersData” )
.find()
.then( (results) => {
// handle the results
} );
It wasn’t really specific on how to handle the results, and I tried looking elsewhere, have no idea syntactically how to pull out the user’s login email. I also stumbled upon the UserInfo feature, but I ran into a similar issue; it also wasn’t specific in terms of how to actually apply it.

So currently I am stuck on steps 2 and 3. Any specific , detailed code or help would be much appreciated.

Edit: To anyone who may be looking to do what I am doing, there is a MUCH simpler way: while this may be helpful, you can restrict the data that appears from a Form Submission data collection by using a filter on it. Wix provides a filter and, using the link from step 5 above, you can restrict the data that is shown to a specific user, by limiting them with the “Owner” filter, and it only shows the user the data that they have inputted when logged in.

Hello Divya Khatri,

perhaps this example can help you.
https://russian-dima.wixsite.com/meinewebsite/user-infos

You can use the following TEST-USER log-in-data:

test@account.com
PW: 12345

Thank you! However, I’m still now completely sure on how to add it to my data collection properly

Thank you! However, I’m still now completely sure on how to add it to my data collection properly

Sure or unsure?

EDIT:


My advise for you is —> DO EVERYTHING STEP BY STEP!

You have here several actions which have to be done.

  1. Getting the ID or eMail of the user.
  2. Get/find results from MembersPrivateData
  3. Collecting eMail → write-action into a database
  4. Put together data and so on…

Now slowly and smoothly!
Start with STEP-1, for example get the eMail of a user.
When you have done it, go and do the NEXT-STEP.

It is normal, that you are totaly confused, because trying to do all actions at once.

apologies. I meant unsure. Also, when I tried to incorporate this into my code, it didn’t work:

function show_eMail (parameter) {console.log(“Show-ID started.”)
let eMail = wixUsers.currentUser.getEmail()

.then( (email) => { 
    let userEmail = email; 
    console.log(userEmail) 
    $w('#TXToutput3').text = (userEmail) 
} ); 

When incorporating it, I did this:

export function button2_click(event) {

let eMail = wixUsers.currentUser.getEmail()
.then( (email) => {
let userEmail = email;
console.log(userEmail)
$w( ‘#text39’ ).text = (userEmail)
} );
}

However, it didn’t work, and I am not entirely sure why

Do it like a checklist!

  1. Got User-ID ? ----> Checked (confirm it with a CONSOLE-LOG, so that you can be sure, that this part of your CODE really works and that you get the right output.

When everything is ok and works —> go to the next step and expand your code.

EXAMPLE:

  1. I need to get User-Email: —> ok let’s GO
import wixUsers from 'wix-users';

function show_eMail () {console.log("Show-ID started.")
    let eMail = wixUsers.currentUser.getEmail()
 
    .then( (email) => {
        let userEmail = email;
        console.log(userEmail)  //<---- check if OUTPUT allright
        $w('#TXToutput').text = (userEmail)
    });

Ok, first step done.

  1. Ok, perhaps i will also need a User-ID:
function show_ID (parameter) {console.log("Show-ID started.")
    let userID = wixUsers.currentUser.id
    console.log(userID) //<---- check if OUTPUT allright
    $w('#TXToutput').text = ("Your User-ID is " + userID)
}

Booooom! I got my User-ID. What is my next step???

  1. Collecting emails. Ok to collect them i need a database and i have to write them somehow into my database.
import wixData from 'wix-data';

// ...

let toInsert = {
  "title":        "Mr.",   //just copy and paste from API-REFER.
  "first_name":   "John",  // just modify to the own needs
  "eMail":    	  userEmail //yeah my first combination!
};

wixData.insert("myDatabase", toInsert)
  .then( (results) => {
		let item = results; 
		//here we do not forget to do a CONSOLE-LOG to be SURE !
	} )
	.catch( (err) => {
		let errorMsg = err;
	} );

And so on…

Hey! Thank you so much! This was super helpful, and the emails are getting collected! I just wanted to ask what this line does from your step 3:
.then((results) => {
let item = results;
//here we do not forget to do a CONSOLE-LOG to be SURE !
})
. catch ((err) => {
let errorMsg = err;
});
I added console.log(item) where you put the comment, and it printed “{…}” I wasn’t sure what the .then actually does, and what the “results” is supposed to contain. From my understanding the .then statement is some sort of Promise where you don’t have to know the variable yet to use it, but I am confused on what those lines and the result are and do.

Thank you again for all of the help.

Hello again,

yes with “.then” you are waiting till the promise was resolved —> then <— the code continue his job. The code do a query of the database of your choice.
It collects all the all the info of the database into an array-bject. That’s why you see the curly brakets ----> { }.
Do some console-logs in the —>.then<— part.

console.log(results)
console.log(results.items) //<--- (items or item, not sure)
console.log(results.items[0].title)
console.log(results.items[1].title)
console.log(results.items[2].title)

All this stuff you also can see in my examples :wink:

https://russian-dima.wixsite.com/meinewebsite