# Saving current user email with befortInsert hook

**URL:** <https://forum.wixstudio.com/t/saving-current-user-email-with-befortinsert-hook/31226>\
**Category:** Ask the community\
**Tags:** wix-members-area, code, question\
**Created:** [December 29, 2019, 1:26am UTC](https://forum.wixstudio.com/t/saving-current-user-email-with-befortinsert-hook/31226 "2019-12-29T01:26:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lubna](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/lubna/32/3202_2.png) [@lubna](https://forum.wixstudio.com/u/lubna)\
**Post date:** [December 29, 2019, 1:26am UTC](https://forum.wixstudio.com/t/saving-current-user-email-with-befortinsert-hook/31226/1 "2019-12-29T01:26:43Z")

</div>

I have a form to collect data but I need the user’s email without adding an email field to the form so I’m using the beforInsert hook but it’s not working. What is the best way to automatically add the user email on submit.

The code I tried and didn’t work

```javascript
wixData.query("Members/PrivateMembersData")
.eq("_id", item._owner)
.find()
.then((results) => {
if (results.items) {
item.email = results.items[0].loginEmail;
} 
return item;
})

```

and

```javascript
let user = wixUsers.currentUser,
userEmail;
user.getEmail()
.then((email) => {
userEmail = email;
});
item.email = userEmail;
return item;

```

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [December 29, 2019, 2:23pm UTC](https://forum.wixstudio.com/t/saving-current-user-email-with-befortinsert-hook/31226/2 "2019-12-29T14:23:18Z")

</div>

If you know that the user who fills out the form is going to be a logged in site member, then you can simply set up a read only user input field that is connected to the Wix Members app Members/PrivateMembersData collection already.

As the site member is already logged in, the email shown here will be the site member’s own email specific for that site member from the Wix Members collection.

You can have this email hidden or shown on the page and as it is a user input, it will be included in the submit button for your form.

If you want to get it through code then you can by simply using Wix Users API and the getEmail function.  
[https://www.wix.com/corvid/reference/wix-users.User.html#getEmail](https://www.wix.com/corvid/reference/wix-users.User.html#getEmail)

---

<div class="post-metadata">

**Author:** ![lubna](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/lubna/32/3202_2.png) [@lubna](https://forum.wixstudio.com/u/lubna)\
**Post date:** [December 30, 2019, 4:19am UTC](https://forum.wixstudio.com/t/saving-current-user-email-with-befortinsert-hook/31226/3 "2019-12-30T04:19:28Z")

</div>

Thank you for the answer, but how could you connect one input element to 2 datasets, I need to connect it to the members dataset to get the value and to my dataset to save it with the form.
