November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.
Stop! There's a better way.
This snippet is available as a plugin with Gravity Perks, a suite of over 47 premium Gravity Forms plugins!
How do I get started?
- Gravity Forms v1.8 is required to use this snippet.
- Already have a license? Download Latest Gravity Forms
- Need a license? Buy Gravity Forms
- Copy and paste the snippet into your theme’s functions.php file.
- 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.
new GW_Submission_Limit( array(
'form_id' => 86,
'limit' => 2,
) );
Apply to ALL Forms
Apply a submission limit per 24 hours period to ALL forms.
new GW_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.
new GW_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.
new GW_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.
new GW_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.
new GW_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
asfalse
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 oftime_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 thelimit
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 of60 * 60
(or3600
) 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 addressuser_id
: limit by the logged in user’s WordPress user IDembed_url
: limit submissions of a form from a specific embed URLrole
: 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 47+ essential add-ons for Gravity Forms with support you can count on.
Hi, is it possible to limit_by both by IP and field_value? If so what would the limit array look like in that case?
Hi Aaron,
Something like this should do the trick:
new GW_Submission_Limit( array( 'form_id' => 2, 'limit' => array( // "2" is your field ID, "6" is your limit for this field ID 2 => 6 ), 'limit_message' => 'Aha! You have been limited.', 'limit_by' => array( 'ip', 'field_value' ) ) );
Is there a way to allow users to “buy” more submission limit sold as a woocommerce product, and update the user’s limit amount?
Hi Claudio,
This isn’t currently supported with the snippet or with the perk version of this. I will add this to our list of feature requests for the perk.
Hey there, this was working perfectly but now it isn’t, I’m not sure if its an update for Gravity Forms that has broken it?
We were limiting by user_id and now it’s not working for people logged in via MemberPress?
Any ideas?
Using 3.0 of the script,
Configuration
new GW_Submission_Limit( array( ‘form_id’ => 17, ‘limit’ => 1, ‘limit_by’ => ‘user_id’, ‘limit_message’ => ‘
You have already requested a copy of the handbook.Once you\’ve had a chance to read the book it would be great if you could leave us a review on Amazon too!
‘ ) );
Hi Chris,
It still is working for me when I test locally. I suspect there might be something else at play, such as a plugin conflict.
If you have a Gravity Perks subscription, we suggest using the Perk version of this, as it is more up-to-date, doesn’t require manual configuration, and includes support.
Hi! i’ve tried installing the perks, per IP for only 1 submission per 24 hours. so do i set the submission limit to only 1 or? because if i were to set the submission limit to only 1, then other people who logged on to that form are unable to submit the form?
appriciate if you could assist?
thanks
Hi,
I have sent you a reply via email so we can request more information about the issue you’re experiencing. Please check and reply via email.
Best,
Hey guys, thanks for the great snippet.
I have two questions.
Would it be possible to apply this to all forms except predefined ones? As far as I understand it currently we can limit to “all forms” or “specific ones”, but not “all except for…”.
Additionally I would like to use it with gf polls addon, which works fine. Only thing is that I don’t want to disable the form altogether but rather display the form but have the submit button disabled. Reason for this is that users should still be able to see the results of the poll which they can on the form by hitting the “see results” link. Even better of course would be to simply show the results of the poll if limit has been reached.
Cheers
Joe
Hi Joe,
Both your requests will require some customization to the snippet and snippet customization is only available to our Pro Customers. So if you have an active Gravity Perks Pro license, you can get in touch via our support form so we can get our developers to look into your requests. Regarding your second request, we actually already have a snippet that works together with our GP Limit Submissions Perk, to show the Poll results if the limit has been reached.
Best,