Hello Everyone,
I can get current user and display in input field but i want to insert that current value to my own collection.
Thank you
This part you will need to get the user-data…
import wixUsers from ‘wix-users’
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn;
console.log(userId);
console.log(isLoggedIn);
user.getEmail()
.then( (email) => {
let userEmail = email;
console.log(userEmail);
} );
This part here, you will need to insert the value(s) into your collection…
import wixData from ‘wix-data’;
let toInsert = {
“title”: “here my title”,
“first_name”: “John”,
“last_name”: “Doe”
};
wixData.insert(“myCollection”, toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
Ok, it takes to much time to edit this Post from mobile, i will edit it later till end, when i am back home (on my PC).
@russian-dima i already take current user info but i dont know how to insert them ?
import wixData from 'wix-data';
import wixUsers from 'wix-users';
$w.onReady(()=>{
let userID = wixUsers.currentUser.id
let DATA
wixData.query("Members/PrivateMembersData")
.eq("_id", userID)
.find()
.then((results) => {DATA=results
if(results.items.length > 0) {console.log(results)
let firstName = results.items[0].firstName
let lastName = results.items[0].lastName
let loginEmail = results.items[0].loginEmail
$w('#input1').value=firstItem.firstName
$w('#input2').value=firstItem.lastName
$w('#input3').value=firstItem.loginEmail
} else { }
})
.catch( (err) => {let errorMsg = err; console.log(errorMsg)
});
$w('#button1').onClick(()=>{
let toInsert = {
"_id": "00001",
"firstName": DATA.items[0].firstName,
"lastName": DATA.items[0].lastName,
"loginEmail": DATA.items[0].loginEmail,
};
wixData.insert("PastaSiparisi", toInsert)
.then( (results) => {
let item = results; console.log(item)
} )
.catch( (err) => {let errorMsg = err;} );
});
});
Next time please use code-block to show your code.
Don’t want to retype all your code again from a picture! (waste of time)!
@russian-dima thank you very much for your help, i tried to add code-block but didn’t publish.
I tried this code that you wrote, when submit form data where came from current user created new columns in database as firstnamei lastname, and login email not inserted column where i created.
What was the problem here?
Thank you again.
@russian-dima also when submit form just one time, i want user can apply multiple time
@srknszr
Perhaps it would be better when you would show an excerpt of your database.
I do not know which datafields you have in your DB and how are called their IDs. (Screenshot?)
New datafields werde created in your DB, because they did not Matcha existing ones (i think).
They habe to be identical.