I have a preexisting excel database of members to a private club. I’d like to upload this database and only accept Form submissions if members enter their correct email address in corresponding field in said Form.
Is this possible?
I have a preexisting excel database of members to a private club. I’d like to upload this database and only accept Form submissions if members enter their correct email address in corresponding field in said Form.
Is this possible?
Hello Kyle,
You can use the following code to check if the email exists in the database:
wixData.query("myCollection")
.eq("email", emailInput)
.find()
.then( (results) => {
//submit
} )
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
Now to apply this case i would suggest the following ideas:
Add beforeInset Hook that rejects the promise if the email doesn’t exist
export function myCollection_beforeInsert(item, context) {
wixData.query("myCollection")
.eq("email", emailInput)
.find()
.then((results) => {
if (results.length>0)
return Promise.reject();
return item;
}).catch((err) => {
return Promise.reject(err);
})
}
Disable the submit button and enable it only if a matching email is found
wixData.query("myCollection")
.eq("email", emailInput)
.find()
.then( (results) => {
if (results.length>0)
$w(‘#submitButton’).enable();
} )
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
For further information check:
Data query:https://www.wix.com/code/reference/wix-data.WixDataQuery.html#eq
Hooks: https://www.wix.com/code/reference/wix-data.Hooks.html
promises:Promise - JavaScript | MDN
Massa
thanks so much massa!! i will give this a try