Limit number submissions database

Hi!

I would like to limit the number of submissions to my database to 50.
So that after 50 people filled in the form, the limit is reached and no one can fill in the form anymore.
I can’t to this manually, because I’m not able to check the amount of submissions every minute. Is there a way to do this? Can’t find the answer anywhere.

Thanks!
Merel

It is possible. But you should decide what exactly you want. You can check the current number of submissions on page load, and hide the form if it’s over 50.
On the backed you can add a beforeInsert hook that counts the number of submissions and insert a new one only if it’s below the threshold.

Thanks!! And how can I hide the form if its over 50 then? Using hook too?
I’m a newbie when it comes to these things.

@merel_animal before we get into details, you should decide what do you want to happen if the number was under 50, the user started filling the form and it reached to 50 before the the clicked submit. Do you want to reject this submission? to allow this submission (because it was under 50 when the user started filling it?

@jonatandor35 Yes I want to reject that one.

@merel_animal so example, you can add a dataset to your page and refresh it run getTotalCount every X seconds to check if it’s over 50.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#refresh
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getTotalCount

To check it every X seconds, use setInterval() method.
If it’s over 50, $w(“#myForm”).hide() + add a message to the user.
In addition, add a beforeInsert hook on the backend so if the user clicked submit before you had a chance to hide it, it’ll be rejected, and on rejection hide the form and show a message.

@jonatandor35 Not working… got this message ’ An error occurred in one of datasetReady callbacks DatasetError: Operation (getTotalCount) not allowed on write-only dataset’
Honestly, I don’t really understand these codes and where to exactly put them. Maybe it’s better to give up :stuck_out_tongue:

@merel_animal you have to change the dataset settings to Read&Write, instead of Write Only.
As for where to put the code, you can watch tutorials: https://www.wix.com/corvid/video-tutorials and in other videos.
Of course you can give up, but then you won’t be able to have rich and functionality.
On the other hand, you can learn how to use Corvid. It takes some time, but it’s not too complicated.

@jonatandor35 But when I set Read&Write, people are able to look into the data right? That’s not what I want.

@merel_animal “Read” means that your code on the front-end can read it. Regular site visitors won’t be able to look into it. Maybe hackers will be. If you want, you can run a query directly to your collection instead.