Automatic fill

Hello. I have this form (custom) on my wixsite that I want to add auto-fill. The form is for letting people upload their images. I have the input for their name and email, image name. I wondered if it would be possible to , if the user is logged in have their name and email automatically put into the input element. This is because I thought it would be annoying if the person had to put his name and email every time he wants to submit the form. Could anyone lend me a hand?

Look at ths : https://www.wix.com/corvid/reference/wix-users.html , the part “How do send an email …”. That should get you going.

I’m sorry , I still don’t understand.

$w.onReady(function () {get_UserEmail()})

function get_UserEmail() {
 let USER = wixUsers.currentUser
  console.log(USER)
 let eMail = USER.getEmail().then(console.log(eMail))
    console.log(eMail)
}

What would be your simple steps?

  1. At first, get all data of the current (logged-in) user right?
  2. Ok,…
let USER = wixUsers.currentUser

Try to do a ----> console.log() —> console.log(USER)
You should get an OBJECT .

Damn, i am to tired :rofl::sleeping::sleeping::sleeping::sleeping::sleeping: no concentration anymore…

Мы продолжим это завтра😉

Have a good nights sleep​:sleeping::sleeping::sleeping:. Thanks for helping me out today! Oh, I didn’t mean sending a email. That was in the different question(although I did the code correctly but the email wouldn’t come when I tested it.). No, I was asking if I could get the logged in user’s email address and name to be automatically in the input(so they don’t have to enter it every time). But I need the email to be sent too. Could you show me how.

Good morning,

perhaps you can implement this one into your code…

wixLocation.to("mailto:"+"xxxxx@xxxxx.com"+"?subject=MySubject here (  )");

Sorry, is this the code for sending a triggered email?

Hello Arthur,

take a look on this post here, perhaps it will help you.
https://www.wix.com/corvid/forum/tips-tutorials-examples/triggered-emails

Hello, @arthurvalatin :raised_hand_with_fingers_splayed:

You can by getting the user details and apply them to the fields if the user is logged in, here’s an example:

import wixUsers from 'wix-users';
import wixData from 'wix-data';

let user = wixUsers.currentUser;

$w.onReady(function () {
 if (user.loggedIn) { getUserDetails() } 
})

async function getUserDetails() {  
 // Get the user email
 let email = await user.getEmail().then((result) => { return result })
 
 // Now get the user full name
 let name = await wixData.query('Members/PrivateMembersData')
  .eq('_id', user.id).find().then((result) => {
    return result.items[0].nickname;
  })
  
  // Set the fields' values based on the data we have
  $w('#username').value = name;
  $w('#userEmail').value = email;
   
}

Hope that helped ~!
Ahmad

Hello. I had a error in the code.

async function getUserDetails() {
let email = await User.getEmail();
let name = return wixData.query('MembersPrivateData')

I got the error massage for return. So I changed it to awaitUser .

async function getUserDetails() {
let email = await user.getEmail();
let name = await wixData.query('Members/PrivateData')

And the error massage was gone. I will test to see if this works(I might be wrong). Also does the Members/PrivateData mean the database where the emails and names are kept?

It didn’t work​:sleepy:. Should I try again with your code? Or is there something I have missed?(I am sleepy-loosing concentration​:laughing::sleeping::sleeping::sleeping:.)

Sorry Arthur, yeah the return was a mistake, I’ve edited the answer try it now, and tell me what errors you get if you got any.

Yes, it’s the collection where members’ details are kept.

I changed return to await. There was no error massage but, when I went to my live site and went to the form when I was logged in, but my email address and name wasn’t there. What could I do?

Have you changed the input fields IDs to your own IDs?

$w('#username').value = name; // Change username
$w('#userEmail').value = email; // Change userEmail

Yes. I already did that.

$w('#input2').value = name;
$w('#input3').value = email;

input2 is where they put their name in.
And input is where thy put their email in.
Just to let you know, I have connected the form to a dataset.

How about changing the way we set the values …
Change the function body to this

async function getUserDetails() {   
 return wixData.query('Members/PrivateMembersData')
  .eq('_id', user.id).find().then((result) => {
    let item = result.items[0];
    let name = item.nickname;
    let email = item.loginEmail;
    
    $w('#input2').value = name;
    $w('#input3').value = email;
  }).catch((err) => {
      console.warn('Searching the database failed!');
      console.error(err);
  }) 
  
   
}

Do you mean I should replace the code I have with this code? Or just one bit?

No, not the whole code, just the function

I didn’t get an error massage but it didn’t work on the live site.