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.
Can this be used inside of a hook where I can set the gravity form id dynamically from the backend and have this code be called, for example in the ‘init’ hook, but where I can obtain the gravity form id from, instead of putting directly in functions.php? Can you maybe suggest a hook for this?
Hi Solomon,
You should be able to set different feeds without a single line of code per form using our GP Limit Submissions perk.
Best,
My table has two input fields. Suppose I have entered the ID in the first field, and when I enter the same value in the second field, do I have a way to judge before submitting
Hi Lemon,
We already followed up on this via email, but I wanted to post this in the comment thread so other customers could see it.
From what I understand this tutorial to prevent duplicate values in the same form should work: https://gravitywiz.com/gravity-forms-require-unique-values-for-different-fields/
Best,
Can anyone confirm this still works with Gravity Forms 2.5.X?
Hi Jon,
Yes, the snippet works with Gravity Forms 2.5.x.
Best,
Hi, can some one help me to change code to get unlimited number of submissions using “-1” value in “by role” mode?
Hi Luigi,
To set an unlimited number of submissions, you should set the time_period parameter to false
'time_period' => false
.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 ), 'time_period' => false // forever ) );
I am trying to use this to limit a drop-down to the number of times a value can be selected.
Beginner 4:30pm – 5:15pm 5 times Beginner 5:30pm – 6:15pm 10 times Beginner 6:30pm – 7:15pm 3 times
new GW_Submission_Limit( array( ‘form_id’ => 1, ‘limit_by’ => ‘field_value’, ‘limit’ => array( ’18 & up 1:00pm – 2:00pm’ => 2 ), ‘time_period’ => false // forever! ) );
I am sure I am understanding the wrong could you clarify.
Thank you.
Hi Kiel,
This plugin limits by unique field values. It isn’t capable of setting different limits for the different choices. This is a great fit for Limit Choices.
Hello,
I want users to do a quiz where they have to reach 70% good answers. They will get two retakes to get to this percentage.
How can I limit the times they can submit the quiz?
I thought limit them on the email field, because that is an unique value, but when I do this I get an error with the code you provided.
http://snippi.com/s/qzg6l7g
What am I missing?
Hello, Are you attempting to have the quiz only be limited two times in total or do you want the user to get two chances only if they get 70% or higher? Let us know your intent so we could guide you correctly on this one. Best!
Hi there, I’m looking to limit the same form entries per user per month. So user1 and user2 have 10 separate entries per month. I tried the following snippet but I’m getting an error. I have the <?php opening and closing tags removed because it’s already there in the file. Please advise.
new GW_Submission_Limit( array( ‘form_id’ => 1, ‘limit_by’ => ‘user_id’, ‘time_period’ => ‘per_month’ ) );
Hi Julie,
The snippet appears to be working correctly when I tested it on my end. Please refer to our article on snippet troubleshooting for details on installing our snippets.
That said, bellow is the configuration I used on my end, you could copy and paste it and see if it works for you too.
new GW_Submission_Limit( array( 'form_id' => 1, 'limit_by' => 'user_id', 'limit' => 10, 'time_period' => 'per_month' ) );
Hi there, I’ve used the following however, the limit message doesn’t work. Please advise. Thank you.
new GW_Submission_Limit( array( ‘limit_by’ => ‘user_id’, ‘time_period’ => ‘per_day’, ‘limit_by’ => ‘role’, ‘limit’ => array( ‘um_wilson’ => 3, ‘um_dundas’ => 4, ‘limit_message’ => ‘You have reached the maximum # for the day.’ ) ) );
Hi Julie,
You have the limit_by parameter set to both user_id and role which, shouldn’t be so. Either you set the limit_by parameter to user_id and assign an integer to the limit parameter or you’ll set the limit_by parameter to role and set the limit parameter to an array of roles and their limits. Also, I see that you didn’t pass a form ID parameter, so I am guessing this snippet is going to apply to all the forms on the website. In case you want to set the limit for a particular form by role, the snippet configuration will be similar to this;
new GW_Submission_Limit( array( 'form_id' => 2, // Update 2 to the Form ID 'time_period' => 'per_day', 'limit_by' => 'role', 'limit' => array( 'um_wilson' => 3, 'um_dundas' => 4, 'limit_message' => 'You have reached the maximum # for the day.' ) ) );
If I want my merge mark to be allowed only once, what should I do
Hello. could you please let us know some more information as to what you are attempting to do? We would be more than happy to help!
Hi there,
I’m trying to create a form whereby a user rates an instructor, from a dropdown menu. I would only like a specific user id to rate each instructor once every 3 months. How would I go about inputing these values?
Hi Faiz,
If I understand your question correctly, you want only one user to be able to submit the form once in 3 months. If that is correct, then first of all you can use GP populate Anything to populate a hidden single-line text field on the form with current user Id. Then using the current User ID, you’ll set up conditional logic on the form button to only show if the current User Id matches the specific User ID.
The next thing will be to use GP Limit Submission Perk, to limit submissions to the form to once every 3 months using the Time Period. Unfortunately, it’s not possible to use the Snippet above to set the limits to a time period of 3 months, but the GP Limit Submissions Perks offers you that option.
If this doesn’t work for you and you’re a Gravity Perks license holder, you can send us a message via our support form with an export of your form so we can assist you further.
Best,
I am running into WP Supercache issues. It seems as if the limit_message is getting cached. So when I test the form, the cached message with no form is being displayed to all visitors.
Any idea how to not cache the limit message page?
Hi Adam,
This is an issue with WP Super Cache. The solution will be to either adjust the exclusion rule of the plugin, so it doesn’t cache the pages with Gravity forms or you’ll have to use another caching plugin.
Best,
HI, we are experiencing users donating via the Gravity form then the transaction being repeated hours or days later. GForms support has concluded these were from mobile devices which save the browser tabs and reload them when you open the browser possibly causing the submission to be sent again for a new donation.
They have suggested limiting the form, but I just wanted to check to see if there was a limit set to 1, would they not be able to donate again ever? How can you determine it is a repeat of the initial form or a new donation?
Thanks for any help.
Hi Craig,
If the
time_period
parameter isn’t set, they will be limited to 1 submission per 24 hours. If you want to shorten or lengthen that time, simply set thetime_period
you want to limit on.Thanks for your response. So if they open their phone and their browser a day later and have not closed out that tab, it could potentially resubmit that entry again then? But if I limit them by email or for a longer period, they cannot donate more than once, which is not realistic. Ideally the form would disable itself once sent and force a new form with everything cleared from the fields if reloaded.
Hey Craig, depending on the limit, it should not allow the user to submit the entry again until the 24 hour period is over due to the limitation. A possible way you can get around this would be to add a confirmation to your form. That way the user would be brought to a confirmation page and not be able to resubmit the form.
Hello, with your extension it is possible to limit access according to the IP of the device (but not of the network) and the value of a specific field e.g. hotel rooms?
I’m trying to do this:
a menu questionnaire for hotel guests, but I would like customers (many of whom are connected to the wifi network) to be able to send the menu choice only once (because the menu changes every day) and to send it only once per room , in order not to create double menus.
recapitulating my questions are 2:
1) Is it possible to limit access ID, only of the device, but not of the network? 2) it is possible to allow only the insertion of one room at a time, e.g. room 101? and don’t allow the same number to be entered again?
Hello Tobi, thanks for reaching out. 1) the limit will be set by the network as this is how the WordPress system picks up the IP address. Due to this being a built-in function, unfortunately, we cannot change that one. 2)Will this be a dropdown/choice field or a user-defined field? Thanks!
Thanks for the reply
1) is there a solution for this wordpress limit? 2) it will be a number field, where the customer will manually enter the room number (example 101)
Hi Tobi,
1) The IP address that WordPress (or any site) sees is the public WAN IP. It isn’t possible to for it to resolve an individual device’s IP on a network. One solution that could work here is to require the guests to have an account and be signed in to fill out the form. You can then use Limit Submissions to limit each user to once per day.
2) Limiting based on a Number field will work great. Simply add it to the Rule Groups, choose Field Value, and then choose your Number field from the Drop Down.
thanks again for the availability
1) it was a bit what I wanted to avoid, having to register them or communicate credentials for access.
2) so I can Select in the rules: field type> reference field> space to enter the number of rooms?
Hey Tobi, 1)I see. Sadly we do not have a direct solution for this one. 2) You would use a field value: 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. It would work much like the example above for Limit by Field Value. If you currently have our Gravity Forms Limit Submissions perk, and are a Gravity Perks license holder, you can reach out to us through our support channel and we can take a closer look into this for you.
Hi,
A quick question on this… I’m trying to get it to limit submissions from non-signed in users – is that possible? Basically I have the form on one page, but want to prevent a user with the same email address entering the same answer again in one field. I’ve tried the below but it doesn’t work… any idea?
Thanks, Matt
Basic Usage
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 10 => 1, 4 => 1 ), ‘time_period’ => false, // forever! ‘limit_message’ => ‘Sorry, you have already entered for this experience!’ ) );
Hey Matt, this would require us to take a deeper look into the form to solve. Do you have two fields you are trying to use this with? I see you want to validate both fields 10 and 4? This A better solution would be to use the Gravity Forms Limit Submission Perk. If you already have a Gravity Wiz Perk License, go ahead and reach out to our support with your form and we would be more than happy to take a deeper dive.
Thanks Ryan – I wasn’t sure if the plugin allowed you to do so without being a logged in user…
Basically, field 10 is automatically populated with an ID (depending which page you come to the form from), and I don’t want the same person to be able to enter twice with the same email (field 4) on the same ID…
Means I could probably limit it to one entry per email by entry_url as well, but still can’t work out how that works if not logged in?
Cheers, Matt
Thanks for the snippet. Can i exclude some ips? I am using as limi by ip. I want to limit only visitors not admin. Thanks again.
hello, I want to stop the submission of a form when the linked company’s server it sends info to is down for maintenance which is a 2 hr window on a Friday night each week. Would something like this work, I see Gravity forms have restrictions for certain hrs every day but I only want it every Friday for 2 hrs.
Hey Ed, This would be something that could be solved by one of our perk called Conditional Logic Dates. We actually have a tutorial on how to accomplish this found here. Thank you so much. ๐
Could this be used if you wanted to limit the number of times a box was checked by different users. Say there’s a checkbox that says “YES! I want the free gift!”, but you only have 30 units to give away. Could you you specify: ‘limit_by’ => ‘field_value’, ‘limit’ => array( // “25” is your field ID, “30” is your limit for this field ID 25 => 30 ), And once the 30th person who submits the form checks the box, he or she will get the limit message?
Hey Nathan, something like this would be better suited for this snippet. The best solution would be to use our Gravity Forms Limit Checkbox Perk. ๐
Thanks!! Much appreciated!
I am having trouble getting the limit by field value working, it seems to do nothing as far as I can tell, the duplicate submissions still go through.
I copied the code snip, and making sure to change the form ID and field ID inserted it into my functions.php file. If I change the limit_by to ‘ip’ instead of ‘field_value’ the limiter functions so I know I am targeting the form correctly.
The field_value being limited is the Name field in the form right below “Contact Paul Mones & Get Help Today” in the link below, also a snippi of the functions.php file is attached.
https://devmones.wpengine.com/ http://snippi.com/s/as48ukt
Any insight would be helpful, thank you.
Hello BV, This is an interesting question. Could you please try and replace your configuration file with this one http://snippi.com/s/lzynybd. This file will focus in on the First and Last Name fields through the ‘fields’ array. ๐ That should do the trick for you.
Thank you Ryan, that worked perfectly. I appreciate the quick response. Cheers!
Can this be modified to release the limit at a specific time of day rather than a time period?
Hello Cole, sadly we do not have a readily available solution for this one as the time is based on hourly interval ie 24 hours. Our Gravity Forms Limit Submissions plugin would give you a little more flexibility as in time period. If you like you could drop us a support request and we could take a closer look at your site. Thank you!
Thanks Ryan. My goal is to release voting limit at midnight regardless of whether a vote was cast at 12:01 am or 11:59pm. Is that something the plugin allows?
Hey Cole, With the GF Limit Submissions Perk you can actually set by day instead of hourly so this would cut off at the end of each day instead of 24 hours later. If you buy the perk know that we have a 30-Day 100% Money-Back Guarantee and we would be more than happy to answer any questions through support. ๐ Have a wonderful day!
Hey Ryan, I have purchased and installed the Perk. Here’s my goal, which I’m still very unclear if the Perk will resolve.
I will have a poll for best bartender in a group (http://ironbartender.org/test-page/). I want to limit votes per day. NOT 24 hours, but per calendar day. Ideally, I want the limit to be by a cookie so that it is individual based. Via IP will not work because there will be voters on the same networks, such as a home or a business. I do not want to require folks to log in.
So, I set up the Gravity Forms Poll add-on, which includes cookie restriction but only by 24 hour period. That is the problem here. I want to clear the cookie at midnight.
I had understood that the snippet I previously tested would allow time_period: per_day and that would solve the issue. However, it doesn’t seem to override the setting in the Poll add-on itself.
Is there a way to do this with the combo of the Gravity Poll add-on and GP Limit Submission Perk or snippet? Since I’m more designer than developer, this one is hurting my brain now.
Really great snippet, thanks for creating this.
Probably a weird question but is there a way of dynamically updating the limit, say for example if someone sent another form this would then increase the limit on the form the limit has originally been set on.
Thanks again.
Hello Jordan, Do you have another use case for this one? If the user attempts to submit another form, the form would get denied if within the time period. Are you wanting to allow more submissions during a specific time period or will there be a way for the user to override the limited submission? Let us know.๐
Sorry! That was poorly worded, my bad.
I think I’m actually barking up the wrong tree as well. I need to give a user the ability to send a form which initially only allows them to submit it once and then if the form submission is replied/interacted with on the recieving it removes the limit so they can then use the form again.
Hope this makes sense! And thanks in advance.
Hey Jordan, Thank you for that explanation. We do not have an automated way of doing this, but pretty much if you trash the entry that was submitted after replying or interacting with it, this will reset the limit. I hope that helps! ๐
how to show the limit remaining? say you limit 2 submissions per 24 hours, how to display the amount on the page saying 1 submission remaining, etc
Hi Chris, there is a shortcode to support this in the plugin version of this snippet.
Hello,
Is there any way to share the code instead of the plugin shortcode? I’m just using this snippet for coz I can’t afford to buy the plugin for now but I really need to display limit remaining to users so they can monitor how many submissions they can still submit.
Hi SeyntJim, we provide hundreds of free resources but in order to stay in business we do have to charge for some things. Hope you understand. ๐