So far I’m able to get the user ID and use it in an input field on a form with the code I have. How do you do the same for any other field? like for example the owner field, or the image field, or any other?
This is what I have:
import wixUsers from ‘wix-users’;
$w.onReady(function () {
let user = wixUsers.currentUser.id;
$w(‘#input1’).value = user;
});
It automatically fills in the first input on the form.
I want to do the same on the second and third inputs but I want to retrieve other fields, like username, and image, etc…
it does retrieve the field from the collection but for some reason when I click submit on the “comentar” button it doesn’t do anything…
HEEEEEEELLLLPPPP! thanks.
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
let userRole = user.role; // "Member"
Yes, I’m saving the picture and everything else to my own database. I added some code to the second input and it does retrieve the field from the collection but for some reason when I click submit on the “comentar” button it doesn’t do anything…
This is what I added to the second input:
The button won’t work because your code is inside $w.onReady() which runs when the page is loaded.
You need to set an onClick function for the button.
Read a bit here .
Originally, I had the code for my first input inside $w.onReady() and the submit button did work, it wasn’t until I added the second and third inputs that the damn button stopped submitting to my database. I don’t understand why it doesn’t work now even after I added export function button8_onclick() {
$w(“#dataset1”).save();
For some reason when I click the submit button only the first input is sent to my collection and the other fields for inputs 2 and 3 appear blank in the collection.
This is what I have:
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
$w.onReady(function () {
let user = wixUsers.currentUser.id;
$w(‘#input1’).value = user;
let currentUser = wixUsers.currentUser;
currentUser.getEmail().then(email => {
wixData.query(‘Afiliados’).eq(‘email’,email).find()
.then(result => {
let item = result.items[0];
$w(‘#input2’).value = item.nombreDeUsuario;
$w(‘#input3’).value = item.image;
}
);
});
});
Did you get it working? Is the email being sent to your collection?
I am having the same issue. I am retrieving the userId and Email but only userID gets sent to the collection. Email gets sent only sometimes. It’s very flaky.
Following as trying to do basically the same and having issues (I am not a coder by any stretch). Wanting to have the user Name, contact info and photo fill into form.
I found someone on another forum post who commented a solution and when I used the code it helped me. I still had to make sure the value was set when uploading into the database but I think this should get everyone in a better place.