Better Limit Submission Per Time Period by User or IP

This snippet allows you to limit submissions to any (or all) Gravity Forms per a time period (i.e. 30 minutes, 24 hours, 2 days, etc) by a user ID, user role, IP address, a specific form URL, or the value of a specific field.

Modify the “Configuration” portion of the snippet (at the very bottom of the code) to meet your needs. Full usage instructions are below.

Usage

Basic Usage

Apply a submission limit per 24 hour period (default time period) to a specific form.

newGW_Submission_Limit( array(

'form_id'=>86,

'limit'=>2,

) );

Apply to ALL Forms

Apply a submission limit per 24 hours period to ALL forms.

newGW_Submission_Limit( array(

'limit'=>5

) );

Multiple Limiters

Limit the number of a submissions a logged in user can make to specific form from the same embed URL. This would allow you to embed the same form on multiple pages and allow users to submit that form up to the submission limit on each page.

newGW_Submission_Limit( array(

'form_id'=>2,

'limit'=>1,

'limit_message'=>'Aha! You have been limited.',

'limit_by'=>array( 'embed_url', 'user_id' )

) );

Limit by Role

Limit by the logged in user’s role. The limit parameter must be specified as an associative array with the role name as the key and the limit as the value.

newGW_Submission_Limit( array(

'form_id'=>2,

'limit_by'=>'role',

// when "limit_by" is set to "role", "limit" must be provided as array with roles and their corresponding limits

'limit'=>array(

'administrator'=>20,

'contributor'=>5

)

) );

Limit by Calendar Time Period

Limit by a calendar time period (i.e. “day”, “month”, “year”). This means that if you set a limit of “5” and the user reaches the limit on December 31st, they would be able to create five new submissions on January 1st. If you set the limit to a month in seconds (i.e. “2678400”, 31 days in seconds) and the user reached their limit on December 31st, they would not be eligible to create another submission until one of their previous submissions expired from the month-long time frame.

newGW_Submission_Limit( array(

'form_id'=>3,

'time_period'=>'per_month'

) );

Limit by Field Value (with no time period)

Limit by the value of a specific field. This is similar to Gravity Forms “No Duplicates” functionality except you can specify how many “duplicates” are allowed and can use other limiters (i.e. allowing no duplicates per user and more). Also demonstrated is the false value for the time_period parameter which results in the limit applying forever.

newGW_Submission_Limit( array(

'form_id'=>1,

'limit_by'=>'field_value',

'limit'=>array(

// "2" is your field ID, "6" is your limit for this field ID

2=>6

),

'time_period'=>false// forever!

) );

Parameters

form_ids

The form ID(s) of the form(s) you would like to limit. If you want to apply the the same submission limit to all forms, set the form_id as false or do not include this parameter at all. If you would like to limit multiple forms, pass the value as an array of form IDs.

limit

The number of submissions allowed before the user will no longer be able to make additional submission. If limiting by role, the limit should be an array of

time_period

The period of time to which the limit applies. The default time period is one day. In any 24 hour period, if the user reaches the limit they will no longer be able to make new submissions.

If you want to limit by less than a day, you can provide the time period in seconds. A time period of 60 would be one minute (60 seconds). A time period of 60 * 60 (or 3600) would be one hour.

Also supported are three different calendar periods: per_day, per_month, per_year. Calendar time periods are more rigid time periods that “reset” when the calendar time period expires (i.e. one month ends and another begins).

If you do not want to limit by a time period at all, set the time period to false.

limit_message

The message which should be displayed to the user once they have reached the specified submission limit.

limit_by

Specify which identifying data the user should be limited by. Supported values:

ip: limit by the visitor’s IP address

user_id: limit by the logged in user’s WordPress user ID

embed_url: limit submissions of a form from a specific embed URL

role: limit by logged in users role (i.e. “administrator”, “contributor”)

field_value: limit by the value entered into a specific field; works similarly to Gravity Forms’ default “No Duplicates” option, except you can specify how many times the value can be duplicated.

Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks;
a suite of 29+ essential add-ons for Gravity Forms with support you can count on.

Comments

Hello, This is working great but, I need advise on one issue.
How would I apply the limit_message to all forms, regardless of which one is filled.

For example, I have three forms and a user fills one of them out. Now I want all three forms that I specify in forms_ids array to receive the limit_message, because one of the three has been completed.

In other words, the limit message gets applied to all forms in the array, regardless of which form in the array is completed.

but this is limiting a user id to submit the same form 3 times. I need this to become global so that if they submit any 3 forms then try a 4th, they wont be able to. I thought the apply limit per form option would make this happen but it doesn’t seem to do anything.

Hi guys, great snippet, but as you pointed out to Nicolas on August 31, it does not yet work with the latest version of GF.

Could this be the cause of the issue I have with the ‘per_day’ limit combined with ‘by IP’? I have a campaign website with a form for free daily donations (sponsored by companies in our network), you can see it in action here: https://www.getuigengevraagd.nu/gratis-doneren/.

Some users have not submitted the form for months, but still get the message that they already donated today. But I can’t figure out why some users have this issue and other users can use the form daily without any problem.

Can you please help me to find the cause of the issue? If the plugin is up-to-date with the latest version of GF and this solves the issue, I’m ready to buy the plugin.

Is there a way to set the ‘time_period’ to be set from 12:00am to 11:59pm? Instead of the current/default ‘per_day’? An example that I have and is a problem is if someone is voting, and they vote at 11:30am on Tuesday they currently have to wait till 11:30am Wednesday to vote again.

How can I use that to limit a submission to one per logged in user? I do not know the user_id since it changes form user to user. Meaning a user creates an account gets directed to the form an the can submit only once. I would not like use the a field with “No duplicate” option since the user only enters their name and not e-mail address.

Hi Stephan, yup. Just set the limit_by to “user_id”. You don’t actually need to specify a specific user ID. It will simply limit each user (by their user ID) to whatever limit you specify (in this case, 1).

I have a form that is a test and the user can not click submit if they have answered a question wrong. I would like to limit the number of times a logged in user can attempt to pass the test. The form is a multi part form and the last page in the form shows if they passed and allows them to submit or it shows the user they failed the test and will not allow them to submit the form. Can I use this plugin to limit the number of attempts without them actually hitting submit button. can it be limited based on a form element even if it s not submted?