Save User Name and Email to a Collection the user fills out on a members only page

Hello, i am trying to create a complex Platform with Wix Studio. Currently i am having trouble saving a members contact Info into a Collection, after the member (who is logged in) fills out Input elements, which are saved to a collection.

Example: A User logs in on my Website. He then wants to add a Service to his account. I have made a Form with Input elements, where the user can fill out the necessary Information to add a Service. This Information is then stored in a Collection.

In my backend, inside the collection, i can see the Information that was inputed. What i cant see is from which User the Submission was.

I would like it, when a logged in User fills out the input elements, that it automatically saves the users Account Info (for example Name and Email), so i can identify which input belongs to which member in my collection.

I hope this is possible!

Thank you for a response.

The submissions probably have Owner (_owner), but you have to select it to be shown. This is the _id of the user who submitted the form.

Are you using a dataset to submit the data? If so you should use getMember() to get the info from the member, then you can use setFieldValue() to set the value in the dataset.

Hello Simen

Where can i find the ID of the User? I am using the standard Wix Login Form, which then adds any members who login to my Contacts List.

The Form to add a service (created with Input elements) is only accessible for logged in members. This Info is then saved in a Dataset and collected in a collection. Im not sure how to use the getMember() or setFieldValue()… Here are some screenshots:

  • Users Log in with a Custom Sign in Form which then creates a new Contact
  • They can then access the test form i created with input elements, which is connected to a Dataset.
  • After submission, the Data is stored in a Collection in my Backend.

What i need now is for the Name of the Logged in user who submitted the form to appear on the Collection, so i can identify which Data belongs to who.

Could you maybe send screenshots of the getMember() and setFieldValue()?

Cheers!

If you click Manage Forms when viewing the database you’ll see some fields that are unchecked, so they won’t show. One of them is the Owner field, which should contain the _id of the member who added the item to the database.

But, if you want to put the name and email of the person submitting you’ll want some code like this:

import { currentMember } from 'wix-members-frontend';

$w.onReady(function () {
   currentMember.getMember()
  .then((member) => {
    $w('#datasetName').setFieldValue("name", member.contactDetails.firstName + " " + member.contactDetails.lastName)
    $w('#datasetName').setFieldValue("email", member.loginEmail)
  })
  .catch((error) => {
    console.error(error);
  });
});

This will set the values “name” and “email” in the dataset to be the name and email of the user.

Thank you! I found the option to Display Owner on my collection. This gives me the owners ID, as you mentioned!

Where do i need to insert your code for it to work? Im not a programmer nor have i been using Wix for long. Thanks for your help!

Which version of wix are you using?

If you just open the coding panel for the page where the form is you can copy/paste the code. Just select the dataset and you should be able to see it’s name, make it match with where I wrote datasetName (or do the shortcut and change datasetName to dataset1, and it will probably work if that’s the only dataset there)

Thank you so much, it works now!