How do I have a unique user-ID submitted with each submission from a form. For example, users may fill out a form multiple times and I want to view all of their submissions by one unique ID?
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
Hi There:
Sorry I gave you a typo. You need to be using currentUser not currentuserin the if() statement.
https://www.wix.com/code/reference/wix-users.html#currentUser
Thanks, that's in line with what I want!!! I'm having issues getting it to work and I noticed a missing parenthesis to close off the onReady. I added that but it seems to still not populate the database with my userID when I test with a logged in member. my dataset was dataset2 and I named the userID column userId in my collection that is associated with the form. What am I doing wrong?
OK When the user is logged in you can use the wix-users api to get the user's id.
Then all you need is a userId field in your data collection.
With this, assuming you are using a dataset for saving the form, all you should need to do is:
import wixUsers from 'wix-users'; $w.onReady(() => { $w('#datasetname').onReady(() => { if (wixUsers.currentuser.loggedIn) { let userId = wixUsers.currentUser.id; $w('#datasetname').setFieldValue('userId', userId); } } });
Thanks, you’re on the right track. My form is something users fill out once they’re already a member but I don’t see anything that indicates how to return that ID and put it in a database collection. For instance the users might enter the name of an item they’re collecting and submit and then another item and submit. What I’m looking for is a way for my dynamic page that shows their whole “collection” specific to an user. I tried using /{ID} but it’s unique to each record
The only way to do this is to have the user log into your site. Once you have an authenticated user you will have a unique id that you can add to the form submission.
Take a look at this article and see if it helps.
https://support.wix.com/en/article/how-to-create-a-custom-registration-form