Limiting Button Click to One User

Hi Guys, Please please HELP!

So basically i have a simple 3 input form:
Name, Surname and Email address, Note I do not want these people to be members of any kind.

Is there a way that when they click on the submit button it automatically limits this info to only one submission per person based on their email address, as provided above?

2 ways:

  1. Query the database for this email and if exists reject the new insert.

  2. Use the email as _id, and then if you try inserting a new record with the same _id (the same email) it’ll be automatically rejected.

this is what i came up with, but it isn’t working. I don’t want to use hooks.

$w.onReady( function () {
$w( “#input1” ).onChange((event, $w) => {
let ($w( “#teamDataset” ).getCurrentItem();
wixData.query( “reviews” )
.eq( ‘title’ , currentitem.title)
.find()
.then((results) => {
if (results.length > 0 ) {
//id is not unique. show error and disable submit button
$w( ‘#button34’ ).disable();
wixWindow.openLightbox( “Oops” );
} else {
//id is unique. do nothing
}
}). catch ((err) => {
let errorMsg = err;
});
});

So the following code works, but the problem is it “filters” according to the field key, for all the items, and not just the current item.

$w.onReady( function () {
$w( “#input1” ).onChange((event, $w) => {
wixData.query( “reviews” )
.eq( ‘title’ , event.target.value)
.find()
.then((results) => {
if (results.length > 0 ) {
//id is not unique. show error and disable submit button
$w( ‘#button34’ ).disable();
wixWindow.openLightbox( “Oops” );
} else {
//id is unique. do nothing
}
}). catch ((err) => {
let errorMsg = err;
});
});
});

this is what i came up with, but it isn’t working. I don’t want to use hooks. (my title field is the email field)

$w.onReady( function () {
$w( " #input1 " ).onChange((event, $w) => {
let ($w( " #teamDataset " ).getCurrentItem();
wixData.query( “reviews” )
.eq( ‘title’ , currentitem.title)
.find()
.then((results) => { if (results.length > 0 )
{ //id is not unique. show error and disable submit button
$w( ’ #button34 ’ ).disable();
wixWindow.openLightbox( “Oops” );
} else { //id is unique. do nothing
}
}). catch ((err) =>
{ let errorMsg = err;
});
});

So the following code works, but the problem is it “filters” according to the field key, for all the items, and not just the current item.

$w.onReady( function () {
$w( " #input1 " ).onChange((event, $w) => {
wixData.query( “reviews” )
.eq( ‘title’ , event.target.value)
.find()
.then((results) => { if (results.length > 0 )
{ //id is not unique. show error and disable submit button $w( ’ #button34 ’ ).disable();
wixWindow.openLightbox( “Oops” );
} else { //id is unique. do nothing
}
}). catch ((err) => { let errorMsg = err;
});
});
});

In the first code you have a syntax error when you declare the currentitem (you forgot to declare it and you used the “let” in a wrong way.

In the second code you should show the “Oops” lightbox only if the email appears in the query results (you can, for example use the JS .find() method to detect it, or you can include it in the query itself).