Is there a way to see which specific member submitted data into the database?
I have a poll where each member has to vote for someone but they cannot vote for them self, so I need to know if there is a way to see who specifically submitted what vote.
the below code will get the email for the current member logged in, just pass that email to your database when they submit…
import wixUsers from ‘wix-users’;
$w.onReady( function () {
if (wixUsers.currentUser.loggedIn) {
let user = wixUsers.currentUser;
console.log(user);
user.getEmail()
.then((email) => {
let userEmail = email;
console.log(userEmail);
})
}
})
I am just starting to use coding so i just put that code on the page. Is there anything i have to specify in the code? How do i get that email into the database? Do i have to create a new field or can I somehow have the email go to the Title field in the database?
@nhaver13
easiest way to do this if your not good at coding is to place some text on your page and connect the text to your database so that when you submit your form you also submit that text to the database.
use the below code to set the text to the email of the logged in user
import wixUsers from ‘wix-users’;
$w.onReady( function () {
if (wixUsers.currentUser.loggedIn) {
let user = wixUsers.currentUser;
console.log(user);
user.getEmail()
.then((email) => {
let userEmail = email;
console.log(userEmail)
//text1 is the id of your text, change as necessary
$w(‘#text1’).text = userEmail;
})
}
})
@mikemoynihan99
thank you for all the help!!
I’m stuck now on getting the text to connect to the database. I have created a field for the email but no text appears in the database. i have tried the code:
export function button1_click() {
$w(‘#dataset1’).setFieldValue(‘email’,
$w(‘#text37’).text);
}
But still no text appears in the field.
@nhaver13
You said that you have people submitting votes on your site. Just connect it the same way as you did for your votes.
I have the code:
import wixUsers from ‘wix-users’;
$w.onReady( function () {
if (wixUsers.currentUser.loggedIn) {
let user = wixUsers.currentUser;
console.log(user);
user.getEmail()
.then((email) => {
let userEmail = email;
console.log(userEmail)
//text1 is the id of your text, change as necessary
$w(‘#text37’).text = userEmail;
})
}
})
I connected the text37 to my email field in the database but nothing shows up in field in the database. Is there a code i can use to make the users email show up in the correct field?
how were you submitting votes to your database previously ?
@mikemoynihan99
I created a radio group so they have to make a selection. My database only has 2 fields…email and vote. I connected the radio group to the vote field to see who was voted for but i need to be able to see who voted for who.
@nhaver13
ya so just connect the new text to the email field and leave the radio group connected to the vote field.
that way when they submit both fields will be populated at the same time
@mikemoynihan99
I have connected the text to the email field. (vote is blocked out for privacy). This is the result I have gotten every time. The email is always blank. Is there something i have to edit in the database?
@nhaver13
that column is locked, thats what the padlock means. Just create a new field.
@mikemoynihan99
created a new unlocked field and still no luck.
i added
export function button1_click() {
$w(‘#dataset1’).setFieldValue(‘user’,
$w(‘#text37’).text);
}
and that seemed to work for me
Thanks for all the help!!