Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I have a requirement for a competition form to restrict the form submission to once per day, so if the same email address is used to enter more than once in a 24 hour period, they will receive a message to say to try again tomorrow.
Is there a method or additional contrib that would make this possible, if not how could we go about developing one? Cheers, Rob.
Edit: I found previous requests on other versions of the webform module, e.g. https://www.drupal.org/node/597438, https://www.drupal.org/node/1101582 but nothing yet for 8.
Comment | File | Size | Author |
---|---|---|---|
#23 | Screen Shot 2017-12-11 at 13.03.36.png | 55.75 KB | robmccreary |
#21 | Test Form Submission limit Webform Demo Site.png | 181.97 KB | jrockowitz |
#15 | 2929665-submission-limit-interval-13.patch | 202.01 KB | jrockowitz |
| |||
#10 | 2929665-submission-limit-interval-9.patch | 202.57 KB | jrockowitz |
Comments
Comment #2
robmccreary CreditAttribution: robmccreary commentedComment #3
robmccreary CreditAttribution: robmccreary commentedComment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedIt is not too hard to implement and I would probably go with adding submission limit per duration (days, hours, and minute). I am not sure how we would set up a 'duration' element.
It is interesting to note that no one else is really providing this feature, probably because it can be easily handled using custom code. For example, you could create a form alter hook that looks at the number of submissions for a user within a given time period.
Comment #5
robmccreary CreditAttribution: robmccreary commentedCheers for that Jacob, I could simply the requirements to limit form submissions by time (i.e. a day in this case). Much like this that was in 7: https://drupal.stackexchange.com/questions/106344/how-can-i-limit-webfor...
The idea for validating against an email (or field) is someone could create multiple submissions on other IPs to 'hack the system' so to speak, but yeah that would be a validating against a custom field and require custom coding or some kind of rules integration.
Comment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedIt makes sense to port this feature AS-IS from the Webform 7.x-4.x to 8.x-5.x.
Below are the APIs and form elements that need to ported.
Comment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe attached patch has no test coverage. I am not even sure it 100% working yet. I just want to see if I am breaking any existing tests.
Comment #11
robmccreary CreditAttribution: robmccreary commentedThanks for the effort, Jacob. I couldn't apply that patch, but I am happy to test when it is ready.
Comment #15
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedStill not ready but you should be able to apply the patch to latest dev release.
Comment #17
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedIf all the tests passed. Please review this patch. I am going to be (hopefully) tagging that last beta release of the Webform module tomorrow and I would like to get this included.
BTW, you can also check out the feature branch (2929665-submission-limit-interval) via GIT.
Comment #18
robmccreary CreditAttribution: robmccreary commentedLovely stuff, i'll do my best to review this in the morning and try and get another pair of eyes on it as well. Thanks for this effort, Jacob.
Comment #19
robmccreary CreditAttribution: robmccreary commentedHi Jacob, I patched the dev module and no errors were returned, I manually sanity tested a few files and the patch seemed to have applied OK. However i didn't notice a change, perhaps i'm not looking in the right place, i expected a change to: /admin/structure/webform/manage/competition/settings/submissions
Comment #20
robmccreary CreditAttribution: robmccreary commentedThis is on: Drupal 8.4.3 / webform 8.x-5.0-beta23+97-dev
When editing existing form and creating new forms
Cheers.
Comment #21
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe new settings conditionally appear when you set a submission limit.
Comment #22
robmccreary CreditAttribution: robmccreary commentedDoh!
Yeah, i can confirm if you enter a per user submission limit you will get a conditional Per user submission limit interval. I don't understand the functionality of Per user submission limit per source entity field however.
This will return a Drupal message when accessing the form
in terms of bugs i got the following notices:
Notice: Undefined property: stdClass::$webform_open in /docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php on line 1191
Notice: Undefined property: stdClass::$webform_close in /docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php on line 1191
Great work, Jacob!
Comment #23
robmccreary CreditAttribution: robmccreary commentedSo that notice may point to a wider issue in that you can't open the form from a node, open or any selection is not valid, see below:
You can open a form in form settings, however.
Also, tested the time the error message appears and all is fine there.
Comment #24
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@robmccreary Source entity means the limit when the webform is attached to a node or any other entity on the website.
Did you run the all the database updates?
Can you please test this change using...
https://simplytest.me/project/webform/8.x-5.x?patch[]=https://www.drupal...
Comment #25
robmccreary CreditAttribution: robmccreary commentedI did not. And after doing so, of course, everything works as designed. I'm happy. Is there anything else you'd like me to test.
Comment #26
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedWe are all good here. I will commit the patch and tag a new release.
Comment #27
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #29
robmccreary CreditAttribution: robmccreary commentedJacob, i've noticed the following errors, not used them before or since the patch:
The following module is missing from the file system: webform_test_bartik bootstrap.inc:250 [warning]
Unknown path for webform_test_bartik module. [warning]
The following module is missing from the file system: webform_bootstrap_test_theme bootstrap.inc:250 [warning]
Unknown path for webform_bootstrap_test_theme module.