Limit form submission to 1 for each email

I am creating a form but want to limit it so that each individual can only submit the form once.

The form would recognize that the email used was already submitted, and bar the user from making future submissions.

Any advice on how to limit the form to one submission per person based on unique email would be greatly appreciated.

Thanks!

You can use the member Id as form submission id (field key: _id).
The system will not let you submit a new record with the same id and will return an error (error code WDE0074).
Once it returns this error - display an error message “A form with this email has been already submitted”.

J.D., to confirm there is no member’s area so I want to ensure we are using the wording “Member ID” correctly.

The member id is the email field.

Do you have any documentation you can share to implement?

Can you advise? Thanks.

If a visitor can submits the form without logging-in, you should use the email address instead.

I don’t know if you have the option to create a data index (I think it got released to user in the UK and maybe Partners but not to all users yet).

So click the collection ‘More Actions’ menu and see if there’s indexes button.
If there is, click it and create a UNIQE index for your email field (the error for duplicates will be WDE0123 );

If you don’t have the indexes option, you should create a hash UUID that represents the email and use it as an _id.

Option2 (if you don’t have the indexes) -
Go to the Code Packages > NPM and install the uuid-by-string package.
Then on backend/data.js file put something like:

const getUuid = require('uuid-by-string');
export function SubmissionsCollection_beforeInsert((item, context) => {
item._id = getUuid(item.email);
return item;
})
//instead of SubmissionsCollection use your own collection name

Thanks J.D. I have access to indexes and created a collection called “unique_email_eligible” for testing purposes.

From a code perspective, would the code look like the below to connect the custom form with the database/index? Thank you!

const getUuid =require('uuid-by-string');

exportfunction
unique_email_eligible((item, context) => 
{ 
item._id = getUuid(item.email); return item; 
})

  1. Make sure to make the email index Unique

  2. You don’t need the data hook code I posted above (because you went for the index option.

  3. If you connect a dataset to the form it should reject the duplicate submission.

JD you have been super helpful. The indexes are working in that only the first unique form submission (based on email) is accepted. I had two follow up questions summed up in the below video link.

LINK

My follow up questions to you are enumerated in the video but also below:

  1. While the submissions table only accepts the first submission by a unique email, I still get a “thank you for submitting” on the form. Is there a way for the form to have an custom message if it detects that this is the second, third, fourth etc time a user is submitting with the same email?

  2. Is it possible to upload a list of acceptable emails (exclusive) to the content manage and have the form reject any submissions that weren’t on that list of approved emails?

Thanks!

Hi Alison,
Personally, I almost never use these ready-made Wix forms (I create my custom forms instead), so I don’t really know how customizable these form apps are). Maybe you can use the following events to catch the error:
https://www.wix.com/velo/reference/wix-crm/$w-wixformsubmittedevent

https://www.wix.com/velo/reference/wix-crm/$w-wixformsubmittederrorevent

Try to put a console.log() inside and see what error it logs.
If it catches the error (WDE0074) show an text element with the message inside.

If not - create a custom form and either connect it to a dataset (see events here and here ) or run a direct insert .

As for your second question. Sure it’s possible (at least with custom form. Maybe event with the WixForm ).
Create a database collection (“WhiteListedEmails”) and put the emails there. And do something like this:


import wixData from 'wix-data';
let whiteList = [];
wixData.query('WhiteListedEmails').limit(1000).find()
.then(r => {
	whiteList = r.items.map(item => item.email);
})
$w.onReady(() => {
$w('#mailInput').onCustomValidation((value, reject) => {
	if(!whiteList.includes(value)){
		return reject('forbidden');
	}
})
})

P.S. if you don’t want to send the email white list to the front-end due to security consideration, there’s an alternative way to do it in the backend (please let me know).