Help - Current User Email not Writing to DB

Hi all,

I’m working with a website that has multiple forms on separate pages, linked to separate databases. I have code written to get current user email, these forms are only available when members are signed into the site. It works to write to the database but one of the forms does not consistently write the email address that the code pulls in to the form automatically.

This is where it works every time, stlminiclub. This page comtains only one DB “dataset1”. Code:

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';

export function eventSelect_change() {
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("#photoEmail").value = userEmail;
 
  } );
}

export function submitButton_click() {
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("#dataset1").setFieldValue("email", userEmail);

  } );
}

 //The part below is just part of the page code so members can view their dynamic page for the photos they've submitted. This statement is not in the code.
  
export function myPhotos_click() {
 
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"
    wixLocation.to("http://www.stlmini.com/PhotosbyMembers/"+userEmail);
});
}


This is where it rarely works, but sometimes it does, I cannot distinguish what makes it work. https://www.stlmini.com/rsvp. This page includes two DBs, one write-only to “EventRSVP” and one read-only to pull a dropdown list from “EventDetails”. Everything is getting written to the EventRSVP page except the email address that is added to the input field with the code below. Code:

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';

export function RSVPName_change() {
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("#RSVPEmail").value = userEmail;
 
  } );
}

export function submitButtonRSVP_click() {
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("#EventRSVP").setFieldValue("rsvpEmail", userEmail);
  } );
}

Any suggestions would be greatly appreciated! I have racked my brain over this for months…I’m sure it’s probably something simple that I’m just missing. I have checked all of the field names, etc.

Thank you in advance!
Tracy

Wow! That’s a lot of code to digest…

You might want to try adding the setFieldValue in the RSVPName_change() function:

$w("#RSVPEmail").value = userEmail;
$w("#EventRSVP").setFieldValue("rsvpEmail", userEmail);

I hope this helps,

Yisrael

@tracy.behrle did you get this to work. What is your eventSelect_change