Accept Form Submission based on a value in preex database

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:

Massa

thanks so much massa!! i will give this a try