Adding member's email address to submitted form

Hi,
In my site my users can upload forms to the data base.
Once the form was submitted, I want to upload the form and attach the user’s email to it (as one of its fields).

What I did so far is:
I created an invisible text input item and inserted it with the email by code.
Then connected this input element to the right field in the database.

The problem in doing so is that you need to use a promise to get the email address.
From some reason it is not working this way.

My code below:

 $w.onReady(function () {
   $w("#uploaderEmail").hide();
   wixUsers.currentUser.getEmail()   
         .then((email) => {
          $w("#uploaderEmail").value = email;
   });

Important note: The input element ‘uploaderEmail’ does change to hold the right email address but when submitting the form this email does not reach the database.
On the other hand if I insert ‘uploaderEmail’ a specific string by code (inside onReady()), then the string actually gets uploaded to to database.

Any help on how to solve this would be appreciated.
Thanks.

1 Like