Hello
I would like to know how can use the lastname of the PrivateMembersData to put into a another database form ?
For example I've a form with two labels and I would like to put the last name of the member when the form is submitted.
thanks
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.
If the site member is already logged in, then you can simply have a read only user input which is connected to the last name field from the Wix Members app own collection.
https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields#last-name-lastname
As it is site member specific, then only the actual logged in site member's last name will be shown in that user input which you can also have as hidden on load so that it does not show to the user themselves.
Then you can simply include that user input when the user uses the submit button or you do it yourself through the Wix Dataset Save function
Otherwise, you can look at using the getCurrent Item function along with the setDieldValue function, so for example:
$w.onReady(function () { $w("#input1").value = $w("#yourdataset").getCurrentItem().fieldName; }); export function Submit_click(event, $w) { $w('#yourdataset1').setFieldValue('lname', $w('#input1').value); $w("#yourdataset1").save(); }
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getCurrentItem
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue
Finally, you can do it by just using Wix Users API and it is already provided there for you as a sample.
https://www.wix.com/corvid/reference/wix-users.html
How can I get the current user's name?
Use the currentUser property to get the current user's id. Then query the Members/PrivateMembersData collection for the item with that _id.
wixData.query("Members/PrivateMembersData") .eq("_id", wixUsers.currentUser.id) .find() .then( (results) => { lastName = results.items[0].lastName;
.
So it would be something like this on your page.
import wixUsers from 'wix-users'; $w.onReady(function () { }); let user = wixUsers.currentUser; let userId = user.id; let isLoggedIn = user.loggedIn; wixData.query("Members/PrivateMembersData") .eq("_id", wixUsers.currentUser.id) .find() .then( (results) => { lastName = results.items[0].lastName; //rest of your code below//