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.
Thanks for this. With regard to limiting based on a field value, how does that work in relation to a radio button field? I have options for time slots, and I need to limit each time slot to 10 reservations.
Does your snippet for field value simply check if there is a value in that field / not empty when submitted?
Are radio buttons not selected considered empty fields? Thanks in advance for your help.
Hi Brian, this snippet (and the GP Limit Submission plugin) are not designed for inventory. If you want to do inventory, check out Gravity Forms Limit Choices for choice-based inventory and our Better Inventory snippet single Product inventory.
Hello David,
Thx a mil for all the Wizes!
Question: I’m running your Gravity Wiz // Gravity Forms // Automatic Save & Continue function within the Space X-Chimp plugin and would love to combine that with this one: Gravity Wiz // Gravity Forms // Limit Submissions Per Time Period (by IP, User, Role, Form URL, or Field Value).
But it returns this code: Sorry, but your code causes a “Fatal error”, so it is not applied! Please, check the code and try again.
Hi Ignatius, there is likely a rogue character in your PHP file. If you want to send your functions.php to me at david@gravitywiz.com, I’ll be happy to take a look. Please include a link to this message so your message is not auto-archived.
I have GF as a Voting form. I found with the Limit Submissions code, after a vote has been actions, the message comes up to says ‘Aha! You have been limited.
However if I refresh my browser, another vote is added. then a 3rd and 4th etc.
Is there a way to stop this?
Thanks
Dont worry. I just stopped using it. Fixed it.
Just checked the block repeat voters in Polls addon.
No need for this code any more
Roger that, Pete. For what’s it worth, I setup a demo to attempt to recreate this issue but was unable to do so.
how to disable or hide gravity forms all times . show at 10AM and hide 10:15AM . Similar to the Gravity Form settings section -Restrictions-Schedule form
Hi Ras, are you just looking to make the Form Schedule apply daily?
HI David, I want to make the online doctor appointment form… Just be open every day for a limited time.
Schedule form to be active/deactivate (open/close) on specific times (everyday)? what i would like to do is create a form that allows submissions on time X and stops allowing submissions on time Y and prior to time X it displays message A instead of the form and after time Y the page displays message B instead of the form .
Hi Ras, I found your StackOverflow question and answered there: https://stackoverflow.com/questions/58150431/how-to-show-hide-gravity-forms-at-preset-time/58160730#58160730
Hello I have one question I hope some one will help Here is my question I have created one coupon validator using gravity form and invitation addon. Link of addon https://codecanyon.net/item/gravity-forms-invitation-codes/11441758
Now i just want that 1.if user tries to enter wrong code 3 times display captcha. 2. on 4th attempt user enter correct code should see congratulation message.(that is already present) so how could i do that??
Live link https://loveorganics.in/demo/verify/
thank You in advance
You could certainly use this snippet as a basis for this functionality but it is not possible without further customization.
do you have any reference code or anything else so i can figure out how to do it??
or for functionality what i can put there? i tried bt not not getting what i want exact
Thank you for sharing this great resource.
I am having an issue though.
When I have the code live, the forms will just spin. I receive the submission but the user does not see the gravity forms confirmation.
What is causing the conflict?
Here is what I have –
http://snippi.com/s/4x3g71t
Also, am I able to put in multiple form ids? and have multiple limit options? You can see in the snippi link what I am trying to do.
Thank you, Tyler
Hi. Limit submission not work for edit entry in Gravity View. for example user limit to submit 10 submission and then can’t edit previous submission. is any solution for this problem.
Hi Mostafa, you would need to write a bit of custom code that checks if you’re loading the form in Gravity View’s edit more and then only initialize the snippet if you are not.
WIth that said, the plugin version of this snippet automatically handles this. Check it out! https://gravitywiz.com/documentation/gravity-forms-limit-submissions/
Hi David! i try gravity perks and Limit Submission for my Gravity Form but not work! my user after 10 submission cant edit previous entry. Can You explain some code or tricks for me? Thanks
Submit a support ticket and we’ll be happy to dig in. ?
Great snippet. What I need to do if I want to limit more than 1 field? I’ve tried to add input to an array, e.g. ‘limit’ => array(16 => 1, 12 => 1, 16 = > 1) But, it only applies the first, the other two seems not working. Maybe I did it wrong somewhere. Please help.
Hi Mijesh, here is how to do it: https://gravitywiz.com/documentation/apply-class-based-snippet-different-forms/
Is it possible to limit ip by a specific date? I dont want to hide the form on a date but the ip limit would stop on a specific date. For example, it I wanted to limit ip until April 13th at 11:59pm (so 12:00am on April 14th the limit is lifted) what would it be?
This is what I have –
Basic Usage
new GW_Submission_Limit( array( ‘form_id’ => 3, ‘limit’ => 1, ‘limit_by’ => ‘ip’, ‘limit_message’ => ‘You have reached the coupon download limit’, ‘time_period’ => ‘???’ ) );
Your best bet will be to simply wrap the whole initialization in a check. Something like…
if( time() >= strtotime( ‘April 13, 2019 11:59pm’ ) ) { // init code }
Quick question. I’m trying to use a single form that pulls in dynamic information. Right now I have the form setup to pull in a “value” from a post object to a hidden field on the form. The value will be a preset number of signups allowed.
Is there a way using this snippet that I can have the limit requirement pulled from this hidden field so no matter which post loads, the limit will always refer to this unique hidden value?
For the record, I’m pulling this information from a PODs Custom Post Type.
If you dynamically populate a field on the form with the unique value you can use the “field_values” limit type to limit by the value of this field.
Is there a way to limit it based on form submissions that cause an error? Basically, if a user fails to submit the form successfully after 5 times, I’d like to prevent them from seeing/submitting the form. Are there any plugins to handle that?
Hey Jon, we don’t have a solution for this one…
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.
Thanks for your help!!!
Hi Frank, set the “apply_limit_per_form” as
false
to apply to all form IDs you’ve specified.if i have say 5 differen forms but i only want users to be able to submit 3 of them 1 time each, can this be done?
I think it could be accomplished if you create two instances. One so that each of the 5 forms can only be submitted once. And another rule so that the user has a total limit of 3.
And another rule so that the user has a total limit of 3. Not quite sure what you mean by this?
I currently have:
new GW_Submission_Limit( array( ‘limit’ => ‘3’, ‘limit_message’ => ‘Aha! You have been limited.’, ‘limit_by’ => ‘user_id’, ‘apply_limit_per_form’ => ‘false’, ) );
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.
Thanks
I’ve updated the code to work with GF 2.3.6. You can find the updated snippet here: https://github.com/danielkdesigner/gf-no-dupes
Thank you, Daniel! I’ve merged your changes with the core snippet and gave you a shoutout in the update notification at the top of the post. ?
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.
Hi Gert, GF 2.3 introduced some major database changes which is why the snippet no longer works. We do intend to update this snippet but we have hundreds of snippets that also need updates. If you need this functionality immediately, please check out the plugin version: https://gravitywiz.com/documentation/gravity-forms-limit-submissions/
Hi, how to ingrate this in wordpress? or is a part of add-on gravity form ?
This is a snippet that extends Gravity Forms.
Does it work with Gravity Forms 2.3?
Or now we have to buy the paid version?
Hi Nicolas, the snippet version has not been updated to work with 2.3 yet. The plugin version does work with 2.3.
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.
If you set it to 60 * 60 * 24 with a limit of 1, they will not able able to submit the form again until 24 hours from their last submission.
Ok, so there is NO way to have it set from Midnight to Midnight. It is just 24 hours from the time of their submission.
Sorry, I’m confused. per_day is from midnight to midnight. If you’re having issues and need support, I would first try GF Limit Submissions. If you still require support, we can help you here: https://gravitywiz.com/support/
I had a user complain to me that they could not vote when I had the ‘per_day’ set in the ‘time_period’. That is why I was asking if it was a 24 hour from the time of casting a vote.
Hi, your code is amazing.
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.
Is this possible with your code?
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 pre-sale question on Gravity Forms Limit Submissions.
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?
Hi Darin, sorry, GP Limit Submissions only works for limiting on successfully submitted entries.