I have a form that only Members can submit, is there a way that I can have a Member submit only 1 form per hour?
Hi there,
Here is an approach that you can utilize. I wasn’t sure if you wanted to prevent them from even accessing the form in question if they have submitted one in the last hour, or simply disable the submit button. You can work that out.
export function LastHourCheck() {
let thisDateTime = new Date();
let userId = wixUsers.currentUser.id
// In this example memberId is a field in the MemberData collection that stores the actual userId.
wixData.query("MemberData")
.eq("memberId", userId)
.descending("_createdDate")
.find()
.then((results) => {
if (results.items.length > 0) {
// Since it is sorted in descending order, the last submission
// will be the first one in the results array. Capture the
// _createdDate and subtract it from the current datetime value.
let lastEntryDateTime = results.items[0]._createdDate;
// Datetime arithmetic is done in milliseconds. 3,600,000 milliseconds in an hour
if (thisDateTime - lastEntryDateTime < 3600000) {
console.log("Submitted in last hour");
}
} else {
// no previous entries for this member.
}
})
}
I will try this and get back to you thank you