I’m using a radio button (and submit button) to gather user input into a database. I’ve set the radio button value to enter into one field into the database. I’d love some help with coding so that either the radio button OR the submit button also enters the user email address into a second column (but the same record).
Another option would be to create a second record with submit that also collects the user email address into a column.
My goal is to allow users to submit responses, but to be able to see which member submitted them into the database.
I know how to change code to fit my needs, but not how to write the original.
Hi,
Are you managing the members yourself or using the built in members functionality?
If you’re using the built in site members, you don’t have to do anything.
Each record submitted by a site member has an “_owner” field, with that user’s id.
Hi Tomer, thanks for replying. I know I can see with their ID, but I’d like to also see either their name or email, so that I can identify that member. Is there a way to correlate the user ID with other information about that user? Either within this database or elsewhere?
With the site members feature its not yet possible, but we are working on it, meaning in the near future you’ll be able to query the members built in collection yourself.
Unfortunately I cannot commit on a release date 
How do you plan on collecting the email? Do you have a text input element for entering it?
No, I just know there is code that lets you fetch user email addresses if logged in (like this tutorial ). I just was trying to adapt that code to let either my submit or my radio button also enter an item in the database for the user, as well as entering the item value for my radio button.
I understand, you have your own members implementation.
You can add extra information before saving using a “before save” hook, so you can do something like this:
$w("#myDataset").onBeforeSave(() => {
$w("#myDataset").setFieldValue('emailField', userEmail);
});
This will set the field in your collection to whatever value you give it, and it will be saved as part of the current record being saved.
Perfect. I’ve got the code almost working, but I’m missing something. Would you mind taking a look? My dataset is called MyChallenges, and the submit button is button_7. It says I haven’t defined userEmail (I tried, but must have missed something), and that I haven’t defined the selector. Should I be using the button instead of the database?
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
let user = wixUsers.currentUser;
let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”
let isLoggedIn = user.loggedIn; // true
let userRole = user.role; // “Member”
user.getEmail()
.then( (email) => {
let userEmail = email; // “user@something.com”
} );
$w(“#myChallenges”).onBeforeSave( () => {
$w(“#myChallenges”).setFieldValue(‘email’, userEmail);
});
Hi!
It seems like you never actually check if the user is logged in and once you try to getEmail you don’t get anything back and so the variable ‘userEmail’ is undefined since it was assigned with an empty value.
Please look into these guides and references:
How to Build Your Own Members Area Using Code
onLogin( )
Hope it helps!
Doron. 