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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

robmccreary created an issue. See original summary.

robmccreary’s picture

Issue summary: View changes
robmccreary’s picture

Issue summary: View changes
jrockowitz’s picture

It 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.

robmccreary’s picture

Cheers 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.

jrockowitz’s picture

It 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.

  • jrockowitz committed 7fce496 on 2929665-submission-limit-interval
    Issue #2929665: Permit one webform submission per day based on email...

  • jrockowitz committed fdf2930 on 2929665-submission-limit-interval
    Issue #2929665: Permit one webform submission per day based on email...

  • jrockowitz committed 77d23aa on 2929665-submission-limit-interval
    Issue #2929665: Permit one webform submission per day based on email...
jrockowitz’s picture

Status: Active » Needs review
FileSize
202.57 KB

The 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.

robmccreary’s picture

Thanks for the effort, Jacob. I couldn't apply that patch, but I am happy to test when it is ready.

Status: Needs review » Needs work

The last submitted patch, 10: 2929665-submission-limit-interval-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • jrockowitz committed 84e7586 on 2929665-submission-limit-interval
    Issue #2929665: Permit one webform submission per day based on email...

  • jrockowitz committed 78e7bc1 on 2929665-submission-limit-interval
    Issue #2929665: Permit one webform submission per day based on email...
jrockowitz’s picture

Status: Needs work » Needs review
FileSize
202.01 KB

Still not ready but you should be able to apply the patch to latest dev release.

  • jrockowitz committed d824f4f on 2929665-submission-limit-interval
    Issue #2929665: Permit one webform submission per day based on email...
jrockowitz’s picture

If 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.

robmccreary’s picture

Lovely 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.

robmccreary’s picture

Hi 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

robmccreary’s picture

This is on: Drupal 8.4.3 / webform 8.x-5.0-beta23+97-dev

When editing existing form and creating new forms

Cheers.

jrockowitz’s picture

The new settings conditionally appear when you set a submission limit.

robmccreary’s picture

Doh!

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.

administration UI

This will return a Drupal message when accessing the form

User message when blocked from 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!

robmccreary’s picture

So 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.

Error in opening form

jrockowitz’s picture

@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...

robmccreary’s picture

I 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.

jrockowitz’s picture

Status: Needs review » Reviewed & tested by the community

We are all good here. I will commit the patch and tag a new release.

jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

  • jrockowitz committed 65a3176 on 8.x-5.x
    Issue #2929665 by jrockowitz, robmccreary: Permit one webform submission...
robmccreary’s picture

Jacob, 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.