I’m having trouble with
In a site of puzzles’ swap, I have a collection “membres” when I store all recorded members, with some calculated fields (number of puzzles, …).
Working in
Wix Editor
Site link
What I’m trying to do
When a new member registers, it is necessary to create a new item in my collection “membres”, because he is going to add a new puzzle right away.
What I’ve tried so far
I have added this in the velo section :
import wixData from “wix-data”;
$w.onReady(function () {
})$w(‘#registerButton’).onClick((event) => {
let newMember = {
mail: $w(‘#input2’).value.toLowerCase(),
};
wixData.save("membres", newMember);
})
It doesn’t work.
Extra context
I’d double check the id of the collection. You currently have members which seems like it might be a typo?
Are they being registered as Site Members? If so, I’d recommend running this as a backend event (probably wixMembers_onMemberCreated) - this way the item is only created when the member is actually created, and you don’t have to handle it on the frontend checking if the member was created/then saving etc.
OK, I check that as soon as I can, and I give the info.
Sorry for the delay, I have family constraints and I can only work on this site from time to time.
Thank you Noah !
It works !
I have created the events.js file in the backend “library” and just written this :
import wixData from "wix-data"
//récupère l'email et crée un item dans la collection "membres"
export function wixMembers_onMemberCreated(event) {
//const membEmail = event.entity.loginEmail;
const newMember = {
mail: event.entity.loginEmail, //membEmail,
};
wixData.save("membres", newMember);
}
Thank you so much !