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.

November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.

November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.

November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.

November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.

November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.

November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.

November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.

November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.

November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.

November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.

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 46 premium Gravity Forms plugins!

View Plugin Buy Gravity Perks

This snippet replaces both the old Limit User to One Submission Per Time Period and the Limit IP to One Submission Per Time Period snippets.

How do I get started?

  1. Gravity Forms v1.8 is required to use this snippet.
  2. Copy and paste the snippet into your theme’s functions.php file.
  3. 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 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.

Comments

  1. Frank P
    Frank P April 12, 2024 at 8:23 am

    Is there a way to provide a custom message to let the user know why they cannot submit? In my case, we are checking address. We’d like to clearly let the user know that a submission with this address was already submitted/sent?

    Maybe it already does this, but I’m not seeing anything mentioned.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff April 12, 2024 at 9:27 am

      Hi Frank,

      The configuration for this snippet accepts a limit_message parameter, which you can use to set a custom message to display when the limit is reached. Please check the documentation above for more details on this. However, if this isn’t what you want, then you may want to check out our GP Limit Submissions Perk, which has a more user-friendly way of setting a custom message.

      Best,

    1. Scott Ryer
      Scott Ryer Staff August 10, 2023 at 3:06 pm

      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' ) ) );

  2. claudio
    claudio April 22, 2023 at 8:57 am

    Is there a way to allow users to “buy” more submission limit sold as a woocommerce product, and update the user’s limit amount?

    Reply
    1. Scott Ryer
      Scott Ryer Staff April 24, 2023 at 10:52 am

      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.

  3. Chris Wharton
    Chris Wharton November 3, 2022 at 1:40 pm

    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!

    ‘ ) );

    Reply
    1. Scott Ryer
      Scott Ryer Staff November 3, 2022 at 3:12 pm

      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.

  4. unitar
    unitar June 13, 2022 at 2:36 am

    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

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff June 13, 2022 at 8:19 am

      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,

  5. Joe
    Joe June 8, 2022 at 7:39 am

    Hey guys, thanks for the great snippet.

    I have two questions.

    1. 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…”.

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

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff June 8, 2022 at 8:27 am

      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,

  6. Solomon
    Solomon May 26, 2022 at 2:42 pm

    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?

    Reply
  7. lemon lin
    lemon lin October 4, 2021 at 4:19 am

    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

    Reply
  8. Luigi
    Luigi April 28, 2021 at 12:11 pm

    Hi, can some one help me to change code to get unlimited number of submissions using “-1” value in “by role” mode?

    Reply
    1. Dario Space
      Dario Space April 28, 2021 at 12:16 pm

      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 ) );

  9. Kiel
    Kiel March 24, 2021 at 3:05 pm

    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.

    Reply
    1. Scott Ryer
      Scott Ryer Staff March 24, 2021 at 4:09 pm

      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.

  10. Sietse
    Sietse January 14, 2021 at 5:33 am

    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?

    Reply
    1. Ryan Donovan
      Ryan Donovan January 14, 2021 at 10:41 am

      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!

  11. Julie
    Julie January 11, 2021 at 2:27 pm

    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’ ) );

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff January 12, 2021 at 5:29 am

      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' ) );

    2. Julie
      Julie January 15, 2021 at 6:23 pm

      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.’ ) ) );

    3. Samuel Bassah
      Samuel Bassah Staff January 16, 2021 at 12:28 am

      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.' ) ) );

    1. Ryan Donovan
      Ryan Donovan January 8, 2021 at 1:50 pm

      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!

  12. Faiz
    Faiz October 8, 2020 at 12:21 pm

    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?

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff October 8, 2020 at 1:49 pm

      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,

  13. Adam
    Adam July 27, 2020 at 5:24 pm

    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?

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff July 28, 2020 at 7:08 am

      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,

  14. Craig
    Craig June 24, 2020 at 4:50 pm

    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.

    Reply
    1. Scott Ryer
      Scott Ryer Staff June 24, 2020 at 5:06 pm

      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 the time_period you want to limit on.

    2. Craig
      Craig June 24, 2020 at 5:21 pm

      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.

    3. Ryan Donovan
      Ryan Donovan June 24, 2020 at 5:32 pm

      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.

  15. tobi
    tobi June 23, 2020 at 10:18 am

    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?

    Reply
    1. Ryan Donovan
      Ryan Donovan June 23, 2020 at 11:01 am

      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!

    2. tobi
      tobi June 23, 2020 at 1:01 pm

      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)

    3. Scott Ryer
      Scott Ryer Staff June 23, 2020 at 2:21 pm

      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.

    4. tobi
      tobi June 23, 2020 at 2:59 pm

      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?

    5. Ryan Donovan
      Ryan Donovan June 23, 2020 at 3:57 pm

      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.

  16. Matt
    Matt May 15, 2020 at 11:15 am

    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!’ ) );

    Reply
    1. Ryan Donovan
      Ryan Donovan May 15, 2020 at 12:42 pm

      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.

    2. Matt
      Matt May 15, 2020 at 12:56 pm

      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

  17. harvey
    harvey May 14, 2020 at 8:09 am

    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.

    Reply
  18. Ed
    Ed May 8, 2020 at 8:54 am

    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.

    Reply
  19. Nathan
    Nathan April 30, 2020 at 6:55 pm

    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?

    Reply
  20. BV
    BV April 8, 2020 at 10:04 am

    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.

    Reply
    1. Ryan Donovan
      Ryan Donovan April 8, 2020 at 11:17 am

      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.

    1. Cole
      Cole March 17, 2020 at 6:28 pm

      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?

    2. Ryan Donovan
      Ryan Donovan March 18, 2020 at 9:24 am

      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!

    3. Cole Schweikhardt
      Cole Schweikhardt March 18, 2020 at 10:58 am

      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.

  21. Jordan Statham
    Jordan Statham March 5, 2020 at 6:40 am

    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.

    Reply
    1. Ryan Donovan
      Ryan Donovan March 5, 2020 at 11:20 am

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

    2. Jordan Statham
      Jordan Statham March 5, 2020 at 11:27 am

      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.

    3. Ryan Donovan
      Ryan Donovan March 5, 2020 at 11:56 am

      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! 😁

  22. Chris McCoy
    Chris McCoy November 30, 2019 at 10:59 am

    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

    Reply
    1. SeyntJim
      SeyntJim June 21, 2020 at 3:27 am

      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.

    2. David Smith
      David Smith Staff June 21, 2020 at 9:08 am

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

  23. Brian
    Brian November 5, 2019 at 11:30 am

    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.

    Reply
  24. Ignatius Gouws
    Ignatius Gouws October 16, 2019 at 9:43 am

    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.

    Reply
    1. David Smith
      David Smith Staff November 4, 2019 at 8:55 am

      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.

  25. Pete
    Pete October 11, 2019 at 11:10 pm

    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

    Reply
    1. Pete
      Pete October 14, 2019 at 9:56 am

      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

  26. ras
    ras September 28, 2019 at 5:03 pm

    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

    Reply
    1. ras
      ras September 29, 2019 at 11:04 am

      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 .

  27. Swapnil
    Swapnil September 5, 2019 at 3:31 am

    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

    Reply
    1. David Smith
      David Smith Staff September 6, 2019 at 8:45 am

      You could certainly use this snippet as a basis for this functionality but it is not possible without further customization.

  28. Tyler
    Tyler May 7, 2019 at 12:01 pm

    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

    Reply
  29. Mostafa
    Mostafa April 16, 2019 at 3:52 pm

    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.

    Reply
    1. Mostafa
      Mostafa April 18, 2019 at 8:37 am

      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

  30. Mijesch
    Mijesch March 20, 2019 at 3:48 am

    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.

    Reply
  31. Tyler
    Tyler March 19, 2019 at 2:19 am

    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’ => ‘???’ ) );

    Reply
    1. David Smith
      David Smith Staff March 20, 2019 at 9:14 am

      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 }

  32. Brandon
    Brandon March 13, 2019 at 1:22 pm

    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.

    Reply
    1. David Smith
      David Smith Staff March 13, 2019 at 9:34 pm

      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.

  33. Jon
    Jon March 5, 2019 at 7:55 pm

    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?

    Reply
  34. Frank
    Frank January 22, 2019 at 10:37 am

    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!!!

    Reply
    1. David Smith
      David Smith Staff January 30, 2019 at 4:08 am

      Hi Frank, set the “apply_limit_per_form” as false to apply to all form IDs you’ve specified.

    1. David Smith
      David Smith Staff December 14, 2018 at 7:38 pm

      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.

    2. Dylan
      Dylan December 16, 2018 at 12:57 pm

      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

    1. David Smith
      David Smith Staff November 10, 2018 at 6:36 am

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

  35. Gert-Jan Buth
    Gert-Jan Buth October 12, 2018 at 7:49 am

    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.

    Reply
    1. David Smith
      David Smith Staff August 31, 2018 at 7:48 pm

      Hi Nicolas, the snippet version has not been updated to work with 2.3 yet. The plugin version does work with 2.3.

  36. Alex Shores
    Alex Shores August 2, 2018 at 11:49 am

    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.

    Reply
    1. David Smith
      David Smith Staff August 2, 2018 at 2:21 pm

      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.

    2. Alex Shores
      Alex Shores August 2, 2018 at 2:24 pm

      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.

    3. Alex Shores
      Alex Shores August 3, 2018 at 4:57 pm

      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.

  37. Stephan Plesnik
    Stephan Plesnik July 19, 2018 at 6:35 am

    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?

    Reply
    1. David Smith
      David Smith Staff July 24, 2018 at 5:48 pm

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

  38. Darin Densley
    Darin Densley July 5, 2018 at 2:44 pm

    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?

    Reply
    1. David Smith
      David Smith Staff July 5, 2018 at 9:22 pm

      Hi Darin, sorry, GP Limit Submissions only works for limiting on successfully submitted entries.

    1. Joe
      Joe June 12, 2018 at 5:30 am

      Edit: We’ve purchased and installed the perk on both sites, it works as intended, thanks for the tip. Just a shame it’s a subscription model.

    2. David Smith
      David Smith Staff June 12, 2018 at 10:50 am

      Hi Joe, glad the plugin works for you. We’re happy to have you as a Gravity Perks customer! Subscription models make sense for software that is intended to be updated indefinitely over time. Check out our weekly updates. You’ll see that we’re constantly making fixes and improvements to our perks every week! ?

  39. Joe
    Joe June 11, 2018 at 4:24 pm

    Another heads up to say this doesn’t work with Gravity Forms 2.3.2

    Any ETA on a revised version, this is a pretty mission critical snippet and we love it! Many thanks.

    Reply
  40. John O'brien
    John O'brien April 17, 2018 at 12:25 pm

    It looks like this plugin is not compatible with the latest release of gravity forms?

    PHP Notice: An outdated add-on or custom code is attempting to access the ocp_rg_lead table which is not valid in this version of Gravity Forms. Update your add-ons and custom code to prevent loss of form data. Further details: https://docs.gravityforms.com/database-storage-structure-reference/#changes-from-gravity-forms-2-2 in /nas/content/live/asolutions/wp-content/plugins/gravityforms/gravityforms.php on line 5094

    I’m getting duplicate lead submissions after today’s update, so I am only assuming this plugin is no longer functioning (and therefore the culprit.) Thanks!

    Reply
    1. David Smith
      David Smith Staff April 18, 2018 at 9:54 am

      Hi John, yes, this snippet will require an update to work with GF 2.3. We have started a queue for getting these snippets updated. We’ve added your request to this queue. If you’re a Gravity Perks user, send us a support request and we’ll move your request to the top of the queue. Though in this case if you are a Gravity Perks user you would probably want to use GP Limit Submissions instead of this snippet anyways. :)

  41. Olivier
    Olivier April 6, 2018 at 3:19 am

    Hi there,

    Great snippet! I am using it, although I have some questions.

    1. I would like people to fill out the form just once, but… If they made a mistake or would like to add something more, they should get the opportunity to modify the form.

    2. I have implanted this search option for user to search other user that also have filled out the form. When a person is searched and found the page kinda loads again and then I am seeing the form again, that should not be seen.

    Is there a way to solve this? Could you please help me out?

    Thanks,

    Olivier

    Reply
  42. Kenneth
    Kenneth March 6, 2018 at 8:16 am

    Hi

    Thank you for this snippet.

    I want to have a gravity form that only can be submitted once a month (or preferably every 14 days) by every user and I have copied the below code into the bottom of the functions.php file but I get an error message for the “limit message” line and the “limit by” line. Can you see what is wrong?

    Thank you.

    Best Regards

    Reply
  43. Fardeen Chowdhury
    Fardeen Chowdhury February 22, 2018 at 12:24 pm

    Hi,

    <

    p>I’m trying to restrict a form to 1 entry per calendar year, for users of certain roles. It should roll back to allowing 1 entry after December 31st. However when I set up the feed and test the form, it keeps accepting multiple submissions from me even though I added the Administrator role to the limited group. I don’t see the message on the front end stating that I have reached my limit of submissions. See screenshot for my feed setup: [removed]

    Also: is it possible to hide the form entirely from the user if their user account has already submitted an entry for the calendar year?

    Reply
  44. Chris Geelhoed
    Chris Geelhoed January 16, 2018 at 5:23 pm

    Hi David,

    Thank you for this handy snippet!

    I am running into problems getting my form to limit by IP. After some troubleshooting I have found that the GFFormsModel::get_ip() method is returning 127.0.01 on my local site and also on staging.

    It appears to be related to a recent Gravity Forms update: https://docs.gravityforms.com/changes-entry-ip-detection/

    I went ahead and added the filter. This fixed my staging site, but unfortunately broke my local development site.

    Have you seen this issue before? Any insight?

    Thanks again! Chris

    Reply
    1. David Smith
      David Smith Staff January 20, 2018 at 7:27 pm

      Hi Chris, when you say it broke your local dev site, do you mean that the functionality just didn’t work as expected or that there was some sort of actual error? If the latter, what error are you seeing?

  45. Chaz
    Chaz January 15, 2018 at 5:02 pm

    Hi, When limiting by role, is it limited to each user? so If I limit it to two submissions by role “friend” does that mean everyone with the “friend” role can submit two each? Thanks

    Reply
  46. Santiago
    Santiago December 15, 2017 at 11:58 am

    Hi David,

    Thanks for the great work!

    Question, How would you limit by the combination of 2 fields? Situation: the same form is served on all single pages for camp fairs, and the form has a hidden field that also captures the id of the post, so I would like to block submissions if it finds a repeated combination of email + post_ID

    Thanks in advance for the help!

    Reply
    1. Santiago
      Santiago December 15, 2017 at 12:05 pm

      Sorry for the multiple messages, but I would like to clarify what if the limit is based on the email and a custom field, i.e. email + event_date. Thanks

  47. Alain TERRIEUR
    Alain TERRIEUR October 25, 2017 at 11:41 am

    Hi, is it possible to mix parameters liks this : only one time for form 26 and 27 and Limit 19 times for role administrator et 4 for subscriber

    Thank you

    Reply
  48. Matthew
    Matthew October 18, 2017 at 6:45 am

    Hello

    I would like to say that the perks bundle has helped greatly, however I’m stuck at this point.

    I’ve configured a series of forms that enable us to sell gift vouchers for our restaurant. When a customer purchases a voucher, A query string link in a notification is sent to our office which contains all the information captured from the customer.

    Our staff then input the details into our till system which then generates a unique code. When they click that link it takes them to a form where they need to input the unique code, the form is prepopulated with customer data from the query string.

    Upon submission the voucher is sent as an attachment to the customer.

    What I want to do is limit the submission to 1 per transaction. Can this code help me with that?

    Reply
    1. David Smith
      David Smith Staff October 25, 2017 at 12:16 pm

      This snippet will allow you to limit a form to one submission you just need to identify what data you will use to uniquely limit the submissions.

  49. Leo Dunkelberger
    Leo Dunkelberger October 16, 2017 at 5:49 pm

    Hello! I work for a University that needs to use the form often. If there a way I can limit ALL IPS save for the School’s? Thank you!

    Reply
    1. David Smith
      David Smith Staff October 25, 2017 at 12:19 pm

      You could limit by IP and set the limit to whatever you want for all non-University-IPs and then wrap the configuration in a check for the current IP. Here’s the rough idea:

      if( not university IP ) { new GW_Submission_Limit( ... ) }

  50. Frank
    Frank October 16, 2017 at 2:26 pm

    Hey David. Thanks for Great Snippet! if i want user can do only one Paid Transaction and after show error for them that says “You can only buy one ticket” How can i configure? i use gravity view for show result and gravity form for submit. but also Cancelled Transaction Interference with my form and my limit not work good. Thanks

    Reply
    1. David Smith
      David Smith Staff October 25, 2017 at 12:23 pm

      This snippet does not support only counting paid submissions; however, if you’d like to pick up a copy of Gravity Perks, we can send you the plugin version of this snippet and a little code snippet to limit by paid submissions with it. Drop us a line via support.

  51. Smith
    Smith October 9, 2017 at 1:52 pm

    Hey David! thanks for Great Code but…One Thing if i want add 2 form and each form have different condition.. for example form 1: user can send 4 Entire form 2: user can send 1 Entire But Each form same fields. Now how can i add this snippet? Please Help me. :) Thank You.

    Reply
  52. Mass
    Mass October 3, 2017 at 2:15 pm

    Hi – great snipped of code!

    Is there a way to exclude a particular IP address or set of IP addresses, when using the limit by IP address option?

    Reply
    1. David Smith
      David Smith Staff October 15, 2017 at 5:17 pm

      It’s called Gravity Forms Limit Submissions and an early-access version is available to Gravity Perks users now. You can request it via the support form.

  53. John
    John September 27, 2017 at 4:52 am

    Hey David. thank you for Code and Help but one Problem..!! if we want to take Quantity for Every User What should we do now? for Example i want each user just enter 4 entity on his profile and after 4th show error. User Registered is Leader and Want to enter 4 person on profile, each person have name and family and age and i want leader cannot register more than 4 user. Thank You.

    Reply
    1. David Smith
      David Smith Staff September 30, 2017 at 1:54 pm

      Hi John, is the user intended to submit all four on the same submission? or are they submitting a form multiple times for each user?

  54. Rae
    Rae September 18, 2017 at 6:09 pm

    Hi David, really grateful for this code, thank you so much for sharing it. One question (and maybe this isn’t the right place to ask, but): I’m limiting Gravity Form Poll users to 10 votes by IP, and a lot of users are finding that they are being blocked before they get a chance to vote.

    Any ideas why this might be happening? I’m aware that users on the same network might all be accessing from the same IP, but it also seems that mobile users on cell networks are also getting blocked.

    Reply
    1. David Smith
      David Smith Staff September 18, 2017 at 9:57 pm

      Hm, honestly not sure, Rae. The network issue is the only one I was aware of with IP limitations. You might consider having the user submit a valid email address and limiting by that instead?

    2. Rae Heitkamp
      Rae Heitkamp September 19, 2017 at 11:22 am

      Thanks very much David, I think we just had a lot of people on the same networks. Switched to limit by email and everything seems to be going much better. :)

  55. Rob Davis
    Rob Davis September 6, 2017 at 2:10 pm

    Hi, David. I previously used version 2.8 of this snippet successfully. I updated the code to the current version, 2.14, but it crashed my site. I copied and pasted the text file straight from GitHub. Has anyone else reported this issue? Also, I am a Gravity Perks user and am looking forward to having this snippet available as a perk so I don’t crash my site. :)

    Best, Rob

    Reply
    1. David Smith
      David Smith Staff September 6, 2017 at 2:41 pm

      Hi Rob, I wouldn’t expect any fatal errors; however, if you’d like to contact us via the support form, I’ll be happy to send you the current beta for GP Limit Submission. :)

    2. Rob Davis
      Rob Davis September 6, 2017 at 4:42 pm

      Thanks, I sent the email to support. By the way, the reason for the earlier error and crash was a rookie mistake on my part. I pasted the entire snippet into my theme’s functions.php file, including the leading <?php. Duh! If anyone else is reading this, don’t do what I did. Grab the rest of the snippet and ignore the leading line, <?php when copying and pasting.

    3. Rob Davis
      Rob Davis September 6, 2017 at 5:13 pm

      Sorry, one more thing. Would you be able to tell me what’s wrong with the following configuration, please?

      The resulting error message is:

      Warning: in_array() expects parameter 2 to be array, boolean given in /home/theaacn9/public_html/wp-content/themes/theaacn/functions.php on line 412

      In my theme’s functions.php file, line 412 is “$is_specific_form = ! $this->is_global( $form_id ) ? in_array( $form_id, $this->_args[‘form_ids’] ) : false;”

      I am simply trying to prevent double clicks on the Submit button for all the forms on my site.

      Best, Rob

    4. David Smith
      David Smith Staff September 7, 2017 at 8:54 am

      Hi Rob, I would expect that configuration to work. This will be a non-issue once you’re running GP LImit Submissions.

  56. Damian Smith
    Damian Smith August 21, 2017 at 10:27 am

    Hey,

    This seems like a great snippet, but I am having issues with it.

    I am using a paged form (3 pages in total) – When I apply the restrictions of limit:1, per day and by ip, I get the limit message appear on the last page, instead of the forms last page?

    Reply
    1. Damian Smith
      Damian Smith August 22, 2017 at 5:06 am

      Gravity forms has a page option, so my form is spread over 3 pages, with the submit button on the 3rd page.

      But with your code in place, instead of seeing the last page, I get the ‘limit_message’ text instead. I can take a screen recording if I am able to email you?

    2. Damian Smith
      Damian Smith August 22, 2017 at 9:23 am

      I have found the cause of the issue:

      “Gravity Forms Partial Entries Plugin” – because this plugin is saving the data as you progress it’s somehow breaking your code snippet :(

    3. David Smith
      David Smith Staff August 22, 2017 at 4:48 pm

      Ah, interesting issue. We will look into addressing this in the upcoming plugin version of this snippet. If you’d like to take that for a test-drive, pick up a copy of Gravity Perks and drop us a line via the support form.

  57. Zeyad
    Zeyad August 14, 2017 at 7:27 pm

    Hi David – Is it possible to use this snippet by limiting a user from submitting a form OR conditionally showing/hiding a field if a specific time has not elapsed.

    For example, only allow this form to be submitted before 7PM local to the user’s GEO data or only display said field before said time.

    Thanks!

    Reply
    1. Zeyad
      Zeyad August 15, 2017 at 5:38 pm

      Thanks for responding David.

      GP Conditional Logic Dates with the timestamp is something that has to be set up manually.

      In other words, I cannot have it to work in a way where each day at 7PM local time to the user hide the submit button?

    2. David Smith
      David Smith Staff August 16, 2017 at 6:59 am

      Hi Zeyad,

      GP Conditional Logic Dates now supports comparing by “Current Time” which is the user’s local time. Here’s what that would look like (screenshot).

  58. Kerry
    Kerry August 11, 2017 at 9:20 pm

    Thanks so much for this snippet. I’d like to prevent duplicate submissions for 60 seconds. When hitting the back button back to my Gravity Form from my ecommerce site the form is adding a duplicate product to the cart because the Gravity Form is resubmitting again. Does this code look correct? Thank you!!!

    Reply
    1. David Smith
      David Smith Staff August 12, 2017 at 6:14 pm

      Hi Kerry, that looks correct. Try testing via the GF form preview. If it works there, there is a likely a conflict with your ecommerce software.

    2. Kerry
      Kerry August 13, 2017 at 9:06 pm

      Thank you, David! Unfortunately, when I add the functions.php file to my child theme, I’m getting error below and the site goes down. Any idea what might be the issue? Here’s the error log:

    3. Kerry
      Kerry August 15, 2017 at 1:44 pm

      Thank you so much for the snippet and for your help!!! I was able to get it working but am seeing some strange behavior. My form is here: http://elephant-books.com/join/

      Using Chrome on MacOS: I make the selection from the Get Started Gravity Form, click continue, land on Checkout page showing selected item in the order. Click back button. Briefly see the Get Started form before page jumps back to Checkout, now with 2 items in the cart. Click the back button again and this time I don’t go to the Get Started page but instead leave the site altogether to whatever the previous site I was on was before clicking elephant-books.com.

      Using Safari on MacOS: I make the selection on Get Started Gravity Form and click continue to Checkout page. Click back button and am shown previous Get Started page. The churning symbol is showing in the left corner of the form. Efforts to click on continue or make a different selection and click continue do not cause any reaction. Manually pushing the forward button returns me to the Checkout page with only one item in the cart.

      Below is my config code.

      Any thoughts?

      Thanks again!!

    4. David Smith
      David Smith Staff August 15, 2017 at 4:50 pm

      Hi Kerry, it sounds like there might be some sort of conflict in the way your cart is interacting with Gravity Forms. Are you able to recreate this same behavior in GF preview?

    5. Kerry
      Kerry August 16, 2017 at 9:40 pm

      Hi David,

      Seems to work fine in Chrome when in Gravity Forms Preview. Does that tell you anything that could help solve the issue? Thanks for your support!

    6. David Smith
      David Smith Staff August 17, 2017 at 6:58 am

      Hey Kerry, this tells us that the issue is with how your GF + eCommerce integration is processing the form submission. Unfortunately, this is beyond what we can troubleshoot pro bono.

  59. Primoz
    Primoz July 26, 2017 at 9:05 am

    How can I configure this plugin so it would limit the users AFTER they submit the form? This is like a sign-up form for trial usage. I have No Duplicates enabled for email field and it works perfect. Now I would like to also limit by IP address as some users will make new email accounts in order to use the trial period multiple times.

    But I get limit message before the form even appears. Can I achieve to be shown after the form has been submitted?

    Reply
    1. David Smith
      David Smith Staff July 30, 2017 at 9:55 am

      This does limit after the user has submitted the form. You’re only seeing the limit message because you’ve already exceeded the limit.

  60. Mark
    Mark July 25, 2017 at 9:22 pm

    Hi David,

    I am trying to limit the use of our form to once per month per ip address.

    Am I doing something wrong?

    Kind regards,

    Mark

    Reply
  61. Miles
    Miles July 18, 2017 at 6:41 pm

    Great snippet works nicely, I also have Gravity View used to display my submissions and am using the plugin also to allow editing of submissions. I am currently limiting my form so a user can only sumbit 3 times and it works perfectly for the actual form the only problem is, when a user clicks the edit link the message is displayed instead of the filled out form for editing. I would like to still use this snippet is there a way I could use this snippet and have the edit form working? Thank you!

    Reply
    1. Miles
      Miles July 19, 2017 at 12:13 pm

      Thank you for your response, I tried instantiating the snipped like that and now it is not even limiting my form, I have my Gravity View Table above my form and they are both displayed on the same page.

      ex: TABLE OF TEAMS //displays all teams

      FORM TO REGISTER TEAMS //when reaches max teams display message

    2. Miles
      Miles July 20, 2017 at 9:52 am

      Thank you so much for your help David, but the snippet is limiting now but not allowing me to edit my entries using a Gravity View display, it is doing what it did before thinking that the edit entries form is an actual form. I tried using the “embed_url” limiter and it works perfectly except whenever I go to a single entry using Gravity View the form displays because it is a different url. This is what code I put in, I may be doing something wrong.

    3. David Smith
      David Smith Staff July 20, 2017 at 10:16 am

      Hey Miles, it looks like we’ll need to dig deeper on this. This is outside of what we can offer pro bono; however, if you are a Gravity Perks user, we provide complimentary support for our snippets via the support form.

    4. Miles
      Miles July 20, 2017 at 5:59 pm

      WARNING, this snippet for some reason causes some issues in the WordPress back end. Using this plugin: https://wordpress.org/plugins/code-snippets/ instead of adding the snippets to your functions.php file and then using the plugin’s settings to make the snippet only run on the WordPress Front End will solve these issues.

  62. Miles
    Miles July 17, 2017 at 12:13 pm

    Where do I paste this code snippet exactly? I put it before the regular theme’s <?php tag and it crashed my website. I also put it after all of the regular function.php code and it crashed my website also.

    I am trying to paste the whole code provided for the snippet. the <?php tag and all.

    Reply
  63. jack
    jack July 17, 2017 at 1:45 am

    Hi David, what I want to do is- login user can fill out info and submit the form the first time. Next time they click the same link, the form with the old entry data will show up on each field and they can only EDIT and save. Is there a snippet that can do this? If not, how can I achieve this? thanks.

    Reply
    1. jack
      jack July 19, 2017 at 3:42 pm

      thanks David. I use the gravity-forms-sticky-list with this snippet, when I click EDIT, no form will show; when I disable the snippet, the form shows for update OK. What cause the problem, please help.

    2. David Smith
      David Smith Staff July 19, 2017 at 8:06 pm

      Hi Jack, the snippet does know the difference between the initial form submission and subsequent form submissions with the sticky list. You’ll probably need to hire a developer to make these play nice together.

  64. Ryan
    Ryan July 15, 2017 at 12:43 pm

    Hi

    Great (very useful) snippet thank you. I’m using the Multiple Limiters as shown above, but how do I apply the same rules to multiple form ids?

    My code is for form ID 14 but I have another 4 forms I want to apply the same rule to.

    Reply
    1. Omar
      Omar July 13, 2017 at 11:32 am

      I have added the code in below and it work fine for both form but for some reason it also limiting my form ID 2 even though i have not added any limits for that ID/

    2. David Smith
      David Smith Staff July 13, 2017 at 11:47 am

      Hm, I’m not able to recreate locally. Only the specified form IDs are limited on my end. We provide complimentary support for our snippets to our Gravity Perks users. Feel free to pick up a copy and drop us a line via the support form.

  65. Joni Kukkohovi
    Joni Kukkohovi July 12, 2017 at 4:06 am

    Hi,

    Thanks for the snippet. I’m hoping it will solve my issue, but I could use a pointer… My goal it to have the for so that user from one IP can submit the form once a week, but the ‘time_period’ only has day, month and year as parameters.

    Would be great if you could help me out on this.

    Thank you!

    Reply
    1. Joni Kukkohovi
      Joni Kukkohovi July 14, 2017 at 4:39 pm

      Thanks David. Question, is this function available through Gravity Perks or just a snippet?

    2. David Smith
      David Smith Staff July 14, 2017 at 8:16 pm

      Currently, just this snippet. We are getting very close to releasing the perk version. :)

  66. Justine
    Justine July 11, 2017 at 10:45 pm

    This is so helpful – thanks so much for sharing it! I had a question… I only need to limit my form to one entry per user – ever. I have used the snippet setup as below… will this work? Or do I need the field value line as well?

    Reply
    1. Justine
      Justine July 19, 2017 at 3:23 pm

      Hey there – this code actually caused a new problem on my form. While I want to limit a users entries – I still want the user to be able to edit the form. This code turns editing off. Is there anyway I can just limit the initial entry – not edit?

    2. David Smith
      David Smith Staff July 20, 2017 at 10:20 am

      Hi Justine, I just shared this with another user doing the same thing but he said it isn’t working for him. Feel free to give it a try. If it doesn’t work for you and if you are a Gravity Perks user, we provide complimentary support for our snippets via the support form.

    3. Justine
      Justine July 20, 2017 at 5:45 pm

      HI – I tried both of these and both cause issues on my site. The page won’t even load when they are activated. Not sure what’s going on but they don’t work for me.

    4. Miles
      Miles July 20, 2017 at 5:53 pm

      Hi, yes soon after I posted this I realized that I couldn’t access some of the tabs in the WordPress back end. It seems to me that the snippet is running in the wordpress backend which is causing some problems I am using a Snippet importer plugin for my website so I do not have to go into the functions.php file everytime and all I have to do is put in the snippet code there. This plugin also has settings where you can select where you want this snippet to run: “admin panel or front end only”. I then selected front end panel only which fixed the problem. Sorry, I didn’t mean to mess anything up. The link to the plugin I am using is here: https://wordpress.org/plugins/code-snippets/ it runs snippets the exact same way as if you were to put it into your functions.php, try this out and let me know if it helps. Sorry.

    5. Justine
      Justine July 20, 2017 at 9:07 pm

      Hi Miles – I was already using the code in snippets. I have tried front end only after your suggestion – but still causes the same problem. Guess I’m looking for another solution! Thanks for your help.

  67. Rachel
    Rachel July 6, 2017 at 9:47 am

    (1) Any chance you’ll ever be turning this into a plugin, for ease of use by non-coders?

    (2) Is there a way to shorten the amount of code if all we want is to limit all forms by IP address to one submission (per form) per day (no user/role, or field limiters)? I like to limit functions.php code whenever possible to prevent possible errors in the future. Maybe I’m weird.

    Reply
    1. David Smith
      David Smith Staff July 14, 2017 at 12:48 pm

      Hi Rachel, the plugin version is about 85% done! There is no simple way to compress the code.

  68. Dan
    Dan July 1, 2017 at 3:47 pm

    Hi David, I use the one “Multiple Limiters” above to limit each user can only submit one entry on my localhost running WAMP. every time I reboot my computer, the form reappear again and the user can re-enter a form. please help.

    Reply
    1. David Smith
      David Smith Staff July 2, 2017 at 8:05 am

      Hi Dan, I’m not able to recreate this on my own local server. It sounds like you’re having some sort of configuration issue; perhaps you database is being reset somehow? If the entries are still in the Gravity Forms Entries List view, I would expect this to work.

    2. Dan
      Dan July 6, 2017 at 2:51 pm

      thanks David. another question is how to redirect a user to another page. I want to change the line ‘limit_message’ => ‘Aha! You have been limited.’, to something like “EDIT Page”, so the user can click and edit their entry, or directly go to that page. (2) what add-on or snippet can let a user to edit his/her own entry at the frontend?

  69. Michael McPeek
    Michael McPeek June 27, 2017 at 1:43 pm

    This is a great snippet! I installed it as a plugin and I was able to make it limit by email address, but is there a way to make it limit by credit card number? I’m not sure how to specify the subfield for the card number itself (eg. 15_1 or 15.1). using and underscore crashes the page. using a period doesn’t make any result.

    Reply
    1. Michael
      Michael June 28, 2017 at 9:37 am

      Haha, yeah, naturally I tried that just AFTER posting. Thanks again for the great snippet and for your help!

  70. Santiago Cabrera
    Santiago Cabrera June 27, 2017 at 1:05 pm

    Hi, thanks for the great article, Is there a way to make it work even if the admin on the Form Settings page enabled the entry limit in the Restrictions section?. I’m saying this because I’m trying to limit the submissions by email(1 per day) and it works great but only when “Limit number of entries” is not activated.

    Thanks

    Reply
    1. David Smith
      David Smith Staff June 28, 2017 at 11:49 am

      The “Limit number of entires” setting limits by the total number of entries. If that is enabled, it will always override this snippet if the total entry limit is exceeded. Could you elaborate on your use-case for needing both?

    2. Santiago Cabrera
      Santiago Cabrera June 29, 2017 at 3:56 am

      I’m trying to use the form for giveaways, and users can submit multiple times (1 per day). When I use the Form settings to Limit the number of entries, the user is getting blocked by IP, but I would like them to be blocked by a field (email) so multiple users can vote from the same computer.

      In other words, I would like to change the default blocking mechanism (by IP) to something a little more permissive (by email). The question would be if is there an easy way to do that?

      Thanks for sharing your expertise!

    3. Santiago Cabrera
      Santiago Cabrera June 29, 2017 at 8:21 am

      I need the form to be blocked by email. (by default it blocks it by IP)

      So multiple users can submit the form from the same computer as long as they use a different email BUT they should also have the restraint of once per day, so at the next day you can submit the form again using the same email.

      Based on your first response I’m guessing the only way to achieve this is by not setting anything in the admin area, and adding the code snippet in functions.php

      I was looking for a solution that didn’t need me to add stuff to functions.php for every form that needs this functionality, and at the same time hope that nobody sets anything in the backend because it will override the code snippet.

      Hope that clarifies what I need, and sorry for any missunderstanding, English is not my first language. thanks

    4. David Smith
      David Smith Staff June 29, 2017 at 10:38 am

      I understand. This snippet will not override the default Gravity Forms setting. Your understanding is correct. You would need to deactivate the form setting and only use the snippet. Here’s how you can limit by 1 email per day.

      new GW_Submission_Limit( array(
          'form_id' => 1,
          'limit_by' => 'field_value',
          'limit' => array(
              // "2" is your field ID, "1" is your limit for this field ID
              2 => 1 
          ),
          'time_period' => 'per_day'
      ) );

  71. Anthony Giuliano
    Anthony Giuliano June 8, 2017 at 4:39 pm

    Sorry I have another question. For some reason this isn’t limiting a submission from posting when the user hits the back button in the browser after a submission. I would have thought it would do that, do you have any suggestions on how to go about this?

    Reply
    1. David Smith
      David Smith Staff June 8, 2017 at 5:29 pm

      Hi Anthony, I’m not able to recreate this issue. Hitting the back button allows you to see the form again but the extra submission is blocked and returns validation error.

    2. Anthony Giuliano
      Anthony Giuliano June 8, 2017 at 6:01 pm

      That’s so weird. Could it have anything to do with caching? My form page has Cache-Control:no-cache, must-revalidate, max-age=0

    3. David Smith
      David Smith Staff June 8, 2017 at 7:51 pm

      Unlikely. Each submission is a POST request which are almost always excluded from cache. It is on the POST request that the validation is triggered and what will catch erroneous submissions.

    4. Anthony Giuliano
      Anthony Giuliano June 8, 2017 at 9:13 pm

      Hmm, okay I’ll dig deeper and will report back if I figure it out in case any else runs into the same thing. Thanks :)

    5. Anthony Giuliano
      Anthony Giuliano June 8, 2017 at 11:08 pm

      Okay, so it does seem to be preventing the entry, but for some reason Chrome was still following the confirmation redirect. In Safari and I got the expected form validation error message.

  72. Johan Dahl
    Johan Dahl June 8, 2017 at 5:05 am

    Hey,

    Great snippet. I’m including it in a file that I require from functions.php, however I want to use it in a plugin of mine, but then it does not recognize the GW_Submission_Limit class. Not sure if plugins are called before functions.php and that’s the issue? If not, how should I use this snippet if I want to have it in a seperate file required from functions, but use it somewhere else? It does work if I use require_once to load the snippet from the plugin, but preferably I wouldn’t have to do this since its already required from functions.php.

    What am I doing wrong? :)

    Reply
    1. David Smith
      David Smith Staff June 8, 2017 at 8:34 am

      Hi Johan,

      If you want to include this in a plugin, you just need to make sure you’re not initializing the snippet until after both the plugin and snippet are loaded. Try initializing the GW_Submission_Limit class inside an a function on the “init” hook.

    1. Anthony Giuliano
      Anthony Giuliano June 6, 2017 at 9:20 pm

      Sorry I pasted it in the ‘code’ section, but it didn’t come through for some reason. It’s below:

      class GWSubmissionLimit extends GW_Submission_Limit { }

    2. David Smith
      David Smith Staff June 6, 2017 at 9:48 pm

      The snippet class was previously GWSubmissionLimit. This line is for backwards compatibility with people who may still be initializing the snippet using the old class name.

  73. Ivan
    Ivan May 31, 2017 at 8:56 pm

    This is awesome code, thanks so much for supplying it. One question though would it be possible to redirect a user to another page when they reach a limit?

    Reply
    1. David Smith
      David Smith Staff May 31, 2017 at 10:21 pm

      Hi Ivan, this snippet does not currently support that. I’ve added it to the feature requests. :)

  74. Michael
    Michael May 25, 2017 at 4:16 pm

    It looks great. The only issue I have with the code is when I am trying to limit by IP. It limit on Google Chrome and Firefox, but not on Internet Explorer.

    Any suggestions?

    Michael

    Reply
    1. David Smith
      David Smith Staff May 28, 2017 at 12:00 pm

      Hi Michael, I’m not able to recreate this issue. We have a plugin version of this snippet that’ll be available soon(ish). It will include support so if you’re still having this issue we’ll be happy to dig in.

  75. corporatic
    corporatic May 12, 2017 at 3:50 pm

    Hi,

    This works well.

    A bit out of topic, but how can I use the back button in browser to send the form again, now I have to reload the page…

    Thanks a lot

    Reply
  76. Dan
    Dan May 8, 2017 at 7:58 am

    Hi there,

    This is a great snippet! How ever, I get stuck when I try to use the limit by roles section. My code is attached, please could you tell me if there is any reason it should be crashing the website?

    Also, I had to remove <?php from the top of the snippet to prevent the site crashing, I think that is normal?

    As you can see I am a bit of a novice, but am a great fan of your site! I would love to work out how to use this roles part.

    Thanks!

    Reply
    1. David Smith
      David Smith Staff May 8, 2017 at 10:33 am

      Hi Dan, it looks like you’ve specified the “limit” parameter twice. Try removing this line:

      'limit' => 1,

    2. Dan
      Dan May 8, 2017 at 2:13 pm

      Hi there

      I tried that but it didn’t make a difference. Are you sure this should work:

      thanks, see attached code:

    3. David Smith
      David Smith Staff May 9, 2017 at 8:22 am

      Hi Dan, I confirmed your configuration is working on my end. If you need additional support, we do offer complimentary support for our snippets to our Gravity Perks customers. Alternately, if you’d prefer to have us install the snippet for you, we provide that service as well.

    4. David
      David May 11, 2017 at 1:01 pm

      Hi, I’m also having problems with roles – I’d like to limit to specific roles but not ‘administrator’, I’m guessing I can just leave out ‘administrator’, or do you need to put ‘administrator’ => false, ?

      Cheers, David

    5. David Smith
      David Smith Staff May 11, 2017 at 9:10 pm

      Hey David, if you don’t want a role limited, excluding it from the list or role limits all-together should do the trick.

  77. Kenny
    Kenny April 28, 2017 at 10:38 am

    Is it possible to limit a form field_value to a specific user? I have a form that logged in users fill out multiple times. If a person enters in a specific value into one field, can I make it such that nobody else can use that value? However, the original user can then come back and use that value themselves.

    Reply
  78. luca Recchia
    luca Recchia April 27, 2017 at 7:42 am

    Hi. This snippet is really perfet for me. Unfortunately i’m not a developer. In which part of function.php dp I have to put the script? I’ve tryied but it crashed the site.

    Thanks a lot! :-) Luca

    Reply
  79. Ruben
    Ruben April 20, 2017 at 7:46 pm

    Is it possible to limit by total field value over a time period? For instance, a form field has the option of 1-5 that they can select. Can you set the limiter so that once they reach 5 for the month, they can’t submit any more. So if they submit the form and select 3, they could either submit it two more times if they select 1 or one more time if they select 2?

    Reply
  80. AG
    AG April 11, 2017 at 8:40 pm

    Hi, kind of a newbie question: I have several custom functions in my functions.php file, but those are all defined with the “function” keyword. What’s this “new” syntax? What are we creating a new instance of?

    Reply
  81. Asaf Epshtain
    Asaf Epshtain March 12, 2017 at 2:53 pm

    Hi,

    I installed the snippet, but it doesn’t limit my submissions

    Here’s the code I’m using.

    I want to limit by day. I don’t mind if it’ll be 24 hours or calendar day.

    I tried using “per_day”. Got form error message “there’s something wrong with your form marked in red” (nothing was actually marked)

    I tried using 60 * 60 * 24. No limitation. Also when using 86400 value.

    Needless to say all form setting in code are correct.

    Thanks

    Reply
  82. corporatic
    corporatic March 9, 2017 at 4:24 am

    Hi,

    Can I use several LIMIT BY and LIMIT to be able to limit, for example, per role and field type at the same time? or perhaps I must use several new GW_Submission_Limit instances?

    Thanks a lot

    Reply
  83. Reinald
    Reinald March 7, 2017 at 12:25 pm

    Hi David!

    Is there possible to add shortcode into to the “limit_message” so when user reach the limit, it can show content of shortcode instead of text?

    Thank you for any help!

    Reply
    1. David Smith
      David Smith Staff March 7, 2017 at 9:25 pm

      Hi Reinald, you would need to update the snippet to call do_shortcodes() anywhere the limit_message parameter is referenced. :)

    2. Reinald
      Reinald March 10, 2017 at 10:35 am

      David,

      Thank you for replying. I know that I should call do_shortcodes() in my functions.php file but I’m not exactly sure if it works, because I added and tried this but it didn’t work:

    3. David Smith
      David Smith Staff March 12, 2017 at 9:23 pm

      Hi Reinald,

      You’ll need to do it when the message is being output to the screen (not in the configuration). If you search the snippet, you’ll see where the “limit_message” parameter is echoed out. Just wrap that in a do_shortcodes() call and you should be golden.

  84. Andrei G.
    Andrei G. March 3, 2017 at 12:27 pm

    Hi David,

    Thanks for this. I’ve been using this on a site for a while and I may have run into an issue.

    I realized that there are users who are blocked from seeing a form (which is limited to one submission per user, per month), although their last entry was a year ago.

    I looked a bit through the code logic and I think that for the per_month option, the code compares the month of the entry to the current month (maybe without taking the year in consideration).

    So if we use March for example, it compares March to March instead of March 2016 to March 2017.

    The other thing is that I thought that the per_month option is more based on period than on calendar month – so I thought it would calculate number of days since the last entry, which to me, would make more sense.

    The reason is you can fill a form on say March 30 and then another on April 2 and you’d get basically two consecutive entries. For my purpose, the goal of limiting per period (per month) is to trying to prevent users from ordering too many things in a too small timeframe.

    Just wanted to bring this up see if you have any ideas? I wasn’t able to run too many tests on this topic, so maybe you could clarify these points.

    Thanks.

    Reply
    1. David Smith
      David Smith Staff March 4, 2017 at 6:49 pm

      Hi Andrei,

      You were correct about the month and week time periods limiting across all years. This has been fixed and updated above. Thank you!

      As far as limiting by non-calendar-months, the “time_period” parameter supports a time period defined in seconds. For example, here is how you could specify a month in seconds:

      'time_period' => 60 * 60 * 24 * 30,

    2. Andrei G.
      Andrei G. March 9, 2017 at 12:45 pm

      David,

      I updated the script to 2.12 and the problem seems to still exist. If a user has an entry in March 2016, the form is limited, even though I changed time_period to be in seconds instead.

      I also tried with ‘per_month’ as before with 2.12, without success.

      Are you able to run some tests on your end to verify?

      Thanks.

  85. corporatic
    corporatic February 28, 2017 at 7:14 am

    Hi, one more issue…

    I´m using Stickylist to update forms but if limit is reached I can´t edit.

    Any ideas?

    Thanks again

    Reply
    1. David Smith
      David Smith Staff February 28, 2017 at 8:07 am

      This snippet only counts submissions, it doesn’t check if it’s a Sticky List submission or not. If you work with the Sticky List plugin developer, he would probably provide some advice on how to determine if the submission is a sticky list submission.

  86. corporatic
    corporatic February 27, 2017 at 12:16 pm

    Hi, great snippet!!

    Can I limit for userid and role at the same time?

    I need authors to be able to send 1 form, but administrators and editors shouldn´t be able to send any.

    Thanks

    Reply
    1. David Smith
      David Smith Staff February 27, 2017 at 5:24 pm

      You can provide an array of roles to limit by:

      ‘limit’ => array( ‘administrator’ => 0, ‘editor’ => 0, ‘author’ => 1 )

    2. Corporatic
      Corporatic February 27, 2017 at 6:59 pm

      Hi again,

      Thanks a lot for your answer.

      Perhaps I’m missing something…

      I need only authors can send one form but every author must be able to send one.

      How can I achueve that.

      Thanks a lot

  87. Tal
    Tal February 14, 2017 at 10:51 pm

    Hi David! thanks a lot for the code! Im trying to create a cancel rule to limit its functionality when used with gravityview so that new submissions work with the limits but updates remain fully open and accessible. I’ve had some help from help from the gravityview team but its still missing something as im still getting a limit on the edit pages. Im sure this would be extremely useful for many other people. Can you please help? This is the code by Zack: https://gist.github.com/zackkatz/d361149f4961c7d0c67a50d6e959357d

    Thanks a lot!

    Reply
    1. Tal
      Tal February 15, 2017 at 8:13 am

      Hi David,

      Thank you! I’ve actually tried the code but it didnt work for me. Can you please explain how to modify it to work? Im still getting restrictions on the gravityview edit form page.

    2. David Smith
      David Smith Staff February 15, 2017 at 8:29 am

      Hi Tal, unfortunately, we’re not able to provide the level of support required pro bono. If you’re a Gravity Perks customer, we provide complimentary support for our snippets via the support form.

  88. John Doherty
    John Doherty February 14, 2017 at 10:31 am

    Hi there! This is working great for what it says it does and I’m super grateful to you for putting the code out there for all of us to use!

    I want to take it a step further and not quite sure how to do that. After limiting the user by their role, I want to show them the number of submissions they have left in that time period (I’m using month, defined by seconds). So, if a specific role has 12 per month and they’ve used 5, they should see that they have seven left.

    I tried using the shortcode fix, but that apparently pulls on the overall form and I don’t have a submission limit on the whole form.

    Any ideas?

    Reply
    1. John Doherty
      John Doherty February 14, 2017 at 12:45 pm

      Thanks David. I’m getting a “Call to undefined method GW_Submission_Limit” error. I pasted my code.

    2. David Smith
      David Smith Staff February 14, 2017 at 2:03 pm

      Hm, not sure, John. If that is the full file, I can’t see any reason why that error would be generated.

    3. John Doherty
      John Doherty February 14, 2017 at 2:25 pm

      It’s something to do with the code here snippet you linked to. I tried to just implement that and it threw the same error.

      Is it possible that get_entry_count isn’t defined with my functions.php?

    4. John Doherty
      John Doherty February 14, 2017 at 2:44 pm

      Alright, we’re making progress and getting new errors! Now I’m getting a “Call to undefined function wp_get_current_user()” error, which is really weird. Going to make sure GF is all updated.

    5. John Doherty
      John Doherty February 14, 2017 at 5:48 pm

      I’m still getting “Fatal error: Call to undefined function wp_get_current_user() in /nas/content/staging/upcraft/wp-content/plugins/credo-plugin/vendor/class-gw-submission-limit.php on line 276” when I try to implement the echo’s at the bottom. Any ideas?

  89. Paul
    Paul February 1, 2017 at 5:24 am

    Hi David – this is a really useful snippet, thank you

    Is it possible to exclude a specific form? I see that we can use an array to include a range of form IDs, but I’d really like it to apply to all forms, except a specific one – so that you don’t have to update that array every time a new form is created.

    Basically, it’s working nicely to limit the forms that I want to limit, but I just realised that it will be limiting my ‘contact us’ form too :-/

    Reply
    1. David Smith
      David Smith Staff February 1, 2017 at 8:58 am

      Hi Paul, if you don’t have hundreds of forms, here’s an approach you can use to do this.

    2. Paul
      Paul February 1, 2017 at 2:05 pm

      Thanks so much for taking the time to help, much appreciated

      Unfortunately, that approach didn’t work for me though – I think I understand the approach (i.e. create an array of excluded form IDs, and make the limit conditional on the form ID not matching an ID in the array) – but with that extra condition, it does not appear to apply the limit to any forms.

      On debug, I get the following notice: Object of class stdClass could not be converted to int in [filepath-to-my-plugin-containing-the-full-snippet] at line 305 – that line is reproduced below.

      Any further advice you can give would be much appreciated. thanks, Paul

  90. K A
    K A January 26, 2017 at 3:41 am

    Hi David,

    I am using this, and it works great, but while I edit my entry using gravity view, I am getting an error that there was a duplicate. How can I make this check only for the new submission instead of updates as well?

    Thanks

    Reply
  91. javier
    javier January 19, 2017 at 2:32 am

    Buenos días, Tengo un problema con los formularios de Gravity form y no sé cómo solucionarlo. Tengo una página en construcción y uso estos formularios +stripe para comercializar 4 productos/servicios. Cuando le doy a tramitar el pedido aparece el mensaje de confirmación, he elegido la opción de realizarlo en una página, y hasta ahí todo bien. El problema está cuando le a la flecha de ir hacia atrás en el navegador, me vuelve a aparecer el formulario y el solo vuelve a tramitar el pedido. Desde el soporte técnico del plugin me dicen que es un problema de los navegadores, ajeno a ellos y que una opción sería marcar en algún campo la casilla “sin duplicar”, pero veo que esta solución traerá más confusión al usuario. Sabéis si esto se puede arreglar?, o la solución más sencilla seria realizar esa confirmación con la confirmación por defecto de texto? Muchas gracias por vuestra atención. Saludos, Javier

    Reply
    1. David Smith
      David Smith Staff January 19, 2017 at 7:15 am

      Here’s how I would approach this.

      1. Install and activate GP Unique ID.
      2. Copy and paste this snippet into your theme’s functions.php file.
      3. Add a new Single Line Text field to your form.
      4. Enable the “No Duplicates” option.
      5. Add “uid” as the Dynamic Population parameter on the Advanced tab.
      6. Set the Visibility to “Hidden”.

      So, this will populate a Single Line Text field on your form with a Unique ID. The No Duplicates feature will prevent the same unique id from being submitted twice.

    2. javier
      javier January 24, 2017 at 11:40 am

      Hola de nuevo, Voy a realizar los pasos que me has especificado, pero soy algo novato en esto y temo equivocarme.

      Ya tengo instalado Gp unique id.

    3. Copy and paste this snippet into your theme’s functions.php file.
    4. Esto debo pegarlo en functions.php del tema que utilizo o en el plugin Gravity form?. Yo utilizo un tema hijo, en el caso de tener que pegarlo en el tema, estas ordenes no se borraran con las actualizaciones del tema?

      El texto que debo poner en Dynamic Population parameter on the Advanced tab, es simplemente “uid” sin las comillas.

      Gracias por tu tiempo y atencion,

      Un saludo, Javier

  92. Natalie Osborne
    Natalie Osborne January 17, 2017 at 3:04 pm

    I’m hoping you can provide the exact configuration I need if I want to block certain users by their first and last name. It’s a long story why the client needs this. We need a way to block the form submission from approx 10 different people, by using their First and Last name. In our form, these are two different fields. I was messing around with the below configuration, but how do I account for the two field set, AND include multiple names?

    Reply
  93. John
    John January 10, 2017 at 9:33 am

    Can you clarify how the time comparisons such as ‘per_day’ are done? Are WP timezone settings used?

    If I recall correctly, GF stores date_created as UTC time but adjusts it for the WP timezone for display, export, etc. If you use UTC time for a comparison and a visitor is in the ET time zone, the date change will occur at 7 pm instead of the expected midnight.

    Am I correct? If so, is there a simple fix, even just to use a set timezone such as ET by subtracting 5 hours from the UTC time?

    Reply
    1. David Smith
      David Smith Staff January 10, 2017 at 5:25 pm

      Hey John,

      I did a test to confirm and it looks like the date_created is the raw UTC timestamp. You are correct in that what constitutes a day will not align perfectly with every user’s midnight.

      This is something we’ll dig into with the plugin-version. For the snippet, you can probably alter the SQL to handle this logic. See line 162.

    2. John
      John January 10, 2017 at 7:54 pm

      Thanks for confirming.

      To clarify, no matter what you do, you can’t align with every user’s midnight. I think for the plugin version, you should aim to align with the WP timezone setting for the site, whatever that might be.

      That way, at least the site owner gets to say that things align with the site owner’s midnight.

    3. David Smith
      David Smith Staff January 10, 2017 at 9:04 pm

      Thanks for the input, John. My thought was to save the user’s local time via a cookie (so it is accessible server side) and then you can offset the search range for the day based on their specific timezone. Thoughts?

    4. John
      John January 10, 2017 at 10:31 pm

      For my current use case, having the day defined per user wouldn’t work.

      It’s a contest where the form is used to collect entries limited per day based on the rules of the contest. In this situation, it’s common for the rules to be written by the site owner and to specify a uniform time zone, such as the time zone of the site. Having a uniform day is important because it allows setting entry deadlines, picking a winner from among entries on a set day, etc.

      You already allow a timing model that is relative to the user/entry (ie, a floating 24 hour period). I view the calendar timing as more fixed, and the control for fixing them should be in the hands of the site owner.

      Maybe there’s a good use case for your description, but I haven’t come across it.

    5. John
      John January 11, 2017 at 11:17 am

      No, thank you. I tried modifying the SQL like this:

      $time_period_sql = ‘DATE( strtotime(date_created, “-5 hours”) ) = DATE( strtotime(utc_timestamp(), “-5 hours”) )’;

      That doesn’t throw any errors, but it doesn’t work.

      Do I misunderstand what you’re doing with $time_period_sql or do I have an error in trying to subtract 5 hours?

      Any help is appreciated.

    6. David Smith
      David Smith Staff January 11, 2017 at 11:22 am

      That’s all MySQL so PHP functions won’t work there. I think something like this might work:

      $time_period_sql = ‘DATE_SUB( date_created, INTERVAL 5 HOUR) = DATE_SUB( utc_timestamp(), INTERVAL 5 HOUR )’;

    7. John
      John January 13, 2017 at 2:56 pm

      Thanks David. Unfortunately, that didn’t work.

      This works (your original code):

      $time_period_sql = ‘DATE( date_created ) = DATE( utc_timestamp() )’;

      This does not work:

      $time_period_sql = ‘DATE_SUB( date_created, INTERVAL 5 HOUR) = DATE_SUB( utc_timestamp(), INTERVAL 5 HOUR )’;

      Maybe doing math in the SQL statement just won’t work (:

      Any ETA on a version that might fix this? Fixable for a price?

  94. Tahar
    Tahar January 9, 2017 at 2:31 pm

    Hello, thanks for the great snippet here!

    I was wondering if there is a way to show the remaining amount of submission left for a logged in user if this is set by user role, per month. Ideally, this would show in the header.

    I sell monthly subscriptions where people can submit documents for review.

    Thanks!

    Reply
    1. Tahar
      Tahar January 10, 2017 at 9:37 am

      Thanks for the reply David, really appreciated!

      I would have 2 other questions: – Let’s say a user switch plans and has now a new user role (one user role per plan), will the counter “follow” what has been already submitted during the period? – I’m not sure if this is native to Gravity Forms, but if so, let’s say I use an approval scheme were I only want “Approved” submissions to really count, would this be possible?

      Thanks, and sorry if I go too far, I’m new to this!

    2. David Smith
      David Smith Staff January 10, 2017 at 5:26 pm

      If you’re basing it on the User ID, changing the role will not impact this. If you’re doing it by role, then the counter would reset.

    1. David Smith
      David Smith Staff December 24, 2016 at 1:31 pm

      Hi John, I assume you’re using the “field_values” parameter? If so, you’ll need to specify the specified inputs of the complex fields (i.e. 1.3, 1.6) and not the top level field ID (i.e. 1).

    2. John
      John December 24, 2016 at 10:57 pm

      Yes, but to clarify I think it’s “field_value”, not “field_values”.

      I specified the first and last name fields for a name field, along with the unmodified snippet, and it didn’t trigger an error for a name that had been been submitted in the same calendar day.

      I also tried just applying a limit to one component of a complex field, such as 7.3, but that didn’t work.

      On non-complex fields, the snippet works fine.

    3. David Smith
      David Smith Staff December 25, 2016 at 7:08 am

      I would expect you configuration to work… but give this alternate configuration a try anyways (see related code).

    4. John
      John December 25, 2016 at 9:15 am

      Thanks. In a quick test on a name field, the alternate configuration worked. I’ll test address and dropdown when I have more time.

      Merry Christmas!

  95. Razvan
    Razvan December 19, 2016 at 11:41 pm

    Hi and thanks for this awesome snippet!

    I hope you can help me solve an issue I can’t get the hang of: I’m managing a site with several forms and I need to have the same limit (in terms of field value) for some of them, but not all. By “same limit” I mean that if a user submits one of these forms, the limit should come into effect for all of the other forms in this group.

    The code I used almost works, but it puts a limit for each specific form, and the users can submit any of the others, which is not what I am looking for.

    I cannot set a global limit for all of forms in the site because the others don’t include the field whose value I am using to place the limit.

    Thank you in advance for any help you can provide, Razvan

    Reply
    1. David Smith
      David Smith Staff December 20, 2016 at 7:40 am

      I believe you should be able to extend this base class and overwrite the is_applicable_form() method to support a group of forms. Here’s a rough example. Note the array( 1, 2, 3 ). This is where you would put your form IDs that should share the limit.

      http://snippi.com/s/l2w8dd3

    2. Razvan
      Razvan December 21, 2016 at 12:49 am

      Hi David,

      Thanks for the reply!

      I tried replacing my code but got the same result. The limit is still not shared, but placed for each individual form. Is there something I’ve done wrong?

      Regards, Razvan

    3. Razvan
      Razvan December 21, 2016 at 2:21 am

      UPDATE: I think I’ve solved it by changing apply_limit_per_form to false in the code attached. Thanks again for the help!

      Regards, Razvan

  96. Thorsten
    Thorsten December 6, 2016 at 7:49 am

    I have a form with a drop down list containing 4 items, each of the items is available 10 times, so when a user submitted a form with a given item, I like the next time to show the remaining items but also once it reaches 0 tell the user he gets on a waiting list. Any suggestions how to achieve that ? Is there a way to extend the drop down field with these options ?

    Reply
  97. Doug
    Doug October 28, 2016 at 8:58 am

    Hi David,

    Thanks so much for this code! It works beautifully! I was also wondering, like Roberto (https://gravitywiz.com/better-limit-submission-per-time-period-by-user-or-ip/comment-page-5/#comment-265691) if there was a way to show the user how many submissions they have remaining.

    I have a user account page, and based on a user’s role, they are allowed a certain number of submissions per month. I’d like to output a message like “2 submissions remaining this cycle”.

    Reply
    1. Doug
      Doug October 31, 2016 at 9:23 am

      Perfect, thank you! The subtraction calculation wasn’t working correctly for me, then I realized that get_entry_count() was returning a string rather than an integer.

      Works beautifully!

  98. Bradley
    Bradley October 25, 2016 at 11:20 am

    Thanks for this code!

    I got this installed, and I can get it to work for one form. But haven’t been able to add additional forms.

    When I use: new GW_Submission_Limit( array( ‘form_id’ => array(6,7), ‘limit_by’ => ‘user_id’, ‘limit_message’ => ‘You have already voted.’, ‘time_period’ => false ) );

    It doesn’t work. But when I just list one form_id. It does.

    new GW_Submission_Limit( array( ‘form_id’ => 6, ‘limit_by’ => ‘user_id’, ‘limit_message’ => ‘You have already voted.’, ‘time_period’ => false ) );

    Can anyone see my flaw?

    Thanks!

    Reply
  99. Jason Narciso
    Jason Narciso October 24, 2016 at 8:37 am

    Hi David.

    I have a voting type form which shows up on a post-type archive page (in each post output). So all posts are displayed and a user with the specific admin role of “Voter” can vote on each post. Also, the form will currently only show up if the user is logged in with that specific “Voter” role.

    I have this in place where the voter is restricted to one vote per entry, but can I also hide the form or show my ‘limit_message’ on the front-end if a vote has already been logged for that particular user?

    Thank you, appreciate any help.

    Reply
  100. Chris
    Chris October 18, 2016 at 5:10 am

    Hello i am trying to use your submission limits snippet. I am trying to limit my form to one entry per user(subscriber) as its a competition. I tried to insert the following into my functions.php but when i tried to refresh my site i was getting a blank white page, remove the code from functions and it appears again.

    new GW_Submission_Limit( array( ‘form_id’ => 1, ‘limit_by’ => ‘role’, // when “limit_by” is set to “role”, “limit” must be provided as array with roles and their corresponding limits ‘limit’ => array( ‘subscriber’ => 1 ) ) );

    Appreciated if can point me in right direction.

    Reply
  101. Rob Davis
    Rob Davis October 11, 2016 at 4:51 pm

    Hello! Thank you very much for this very useful snippet. I used it successfully to limit votes in an online election to one vote per user with the following:

    new GW_Submission_Limit( array( ‘form_id’ => 29, ‘limit_by’ => ‘user_id’, ‘limit_message’ => ‘You have already voted.’, ‘time_period’ => false // forever! ) );

    I then tried to use a second instance to prevent people from clicking the Submit button twice within 30 seconds on some of my other forms with the following addition:

    new GW_Submission_Limit( array( ‘form_id’ => array(1,18,19,20,21) ‘limit_by’ => ‘user_id’, ‘time_period’ => 30 ) );

    The above crashed my site. Clearly I did something wrong! A help desk agent gave me the following debugging information:

    Parse error: syntax error, unexpected ”limit_by” (T_CONSTANT_ENCAPSED_STRING), expecting ‘)’ in /home/theaacn9/public_html/wp-content/themes/theaacn/functions.php on line 574

    Please let me know if you have any suggestion on what I did wrong. Thank you very much!

    Reply
    1. David Smith
      David Smith Staff October 13, 2016 at 3:16 pm

      Hi Rob, looks like you’re missing a comma before the ‘limit_by’ parameter:

      ‘form_id’ => array(1,18,19,20,21), ‘limit_by’

  102. Phil K
    Phil K October 9, 2016 at 9:38 pm

    Hello, this is a great solution, I am setting up a competition that requires a weekly keyword to enter over 10 weeks.

    Is it possible to restrict it to 1 entry per keyword and match it against their email? So that would basically mean limiting each email to 10 submissions in total. This is for logged out users only.

    is this possible?

    Reply
    1. Phil K
      Phil K October 14, 2016 at 6:22 pm

      Hey David, thanks for the reply. They have to have the correct keyword to win the prize and we also want to limit people from submitting mulitple times.

    2. David Smith
      David Smith Staff October 14, 2016 at 9:30 pm

      This snippet does not validate that the keyword is correct. If the keyword is static, you could simply hide the submit button unless the keyword is entered. This snippet will let you limit how many times a user can submit the form.

  103. Roberto
    Roberto October 5, 2016 at 2:27 am

    Hey, Awesome snippet, I’ve been looking for this for too long, and finally found it and worked great!

    I Have a couple of questions though: 1. Is it somehow possible to show the entries left per user id? 2. How can I reset the limit for a specific user?

    Reply
    1. David Smith
      David Smith Staff October 6, 2016 at 9:54 pm
      1. I sent you some code via Gravity Perks support.
      2. You can search for all entries created by a user on the entry list page and then trash them.
    1. David Smith
      David Smith Staff October 5, 2016 at 11:58 am

      Hi Brad, this is an actual calendar day. To limit by a 24 hour period, you can set the “time_period” to 60 * 60 * 24.

  104. Wes
    Wes September 11, 2016 at 12:19 am

    Hi David,

    First up, this is amazing and thank you.

    I’m having an issue getting this to work. I would like to have a field that a code can be entered into twice a day. Here is my code..

    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 9 => 2 ), ‘time_period’ => ‘per_day’, ‘limit_message’ => ‘

    YOU'VE REACHED THE MAXIMUM ENTRIES FOR TODAY

    A MAXIMUM OF TWO (2) ENTRIES ARE PERMITTED PER PERSON PER DAY. YOU'VE REACHED THE MAXIMUM ENTRIES FOR TODAY, PLEASE COME BACK TOMORROW.

    ‘ ) );

    I get an error as follows:

    Warning: Parameter 1 to array_shift() expected to be a reference, value given in /home/ene3009/wp-content/themes/divichild/functions.php on line 226

    Any ideas? That should work right?

    Cheers, Wes

    Reply
    1. David Smith
      David Smith Staff September 24, 2016 at 12:48 am

      Hm, that looks ok… could you send me an export of your form as well? You should be able to reply to the notification you’ll receive for this comment.

  105. Emilien
    Emilien August 16, 2016 at 4:14 am

    Hey David, thank you for your work on this. Unfortunately I can’t make it work for now… I need to limit 4 forms, by roles and different time periods. So I just pasted your code and adapted the “basic usage” part. Here is the code I get for a single form. The problem is I always get the limit message (in the right language thanks to qtranslate-x, which explains the [:fr][:it][:en][:] tags).

    new GW_Submission_Limit( array( ‘form_id’ => 1, ‘time_period’ => 606024*365, ‘limit_by’ => ‘role’, ‘limit’ => array( ‘administrator’ => 10000, ‘superstar_editor’ => 10000, ‘hero_editor’ => 12, ‘master_editor’ => 7, ‘explorer_editor’ => 3, ‘first_editor’ => 2, ‘free_editor’ => 0, ‘premium_for_life’ => 0, ‘premium_user’ => 0, ‘subscriber’ => 0 ), ‘limit_message’ => ‘[:fr]Vous avez atteint le maximum de créations de pages permis par votre compte en un an.[:it]Hai raggiunto il massimo degli creazioni di pagine consentitti per il tuo conto nello stesso anno.[:en]You have reached the maximum number of pages you can create with your account within a year.[:]’ ) );

    What am I doing wrong? Thank you in advance for your help, have a great day,

    Emilien

    Reply
    1. Emilien
      Emilien August 16, 2016 at 6:07 am

      I found where it came from: it was a specific function into my child-theme, which was calling global $current_user. I just had to change the way the user data is called. I didn’t suspect it at first because I placed your snippet in a custom plugin…

      Seems to work perfectly now. Thank you!

  106. Daniel Gutierrez
    Daniel Gutierrez August 2, 2016 at 7:04 pm

    Hello David! This looks very promising for my need:

    We have developed http://jerseys.innovasport.com/ site, where a user asks to be notified on the launching of a product. We created a form (a custom post embedded in a modal window) where the user types his/her email, and a hidden field that saves the {embed_post:post_title} value. The problem is that I have many duplicated entries. I can’t restrict the mail field because one user could want information on more than one product, but I need to restrict to one email by product. User A email, Product A User A email, Product B is valid, but not twice or more of User A email, Product A. I hope I’m being clear. Basically, is there a way to prevent duplicated entries on multiple fields? Thx in advance!

    Reply
    1. Daniel Gutierrez
      Daniel Gutierrez August 2, 2016 at 7:34 pm

      It worked!!!!! Thank you so much! I just used new GW_Submission_Limit( array( ‘form_id’ => 1, ‘limit_message’ => ‘Aha! You have been limited dude.’, ‘limit_by’ => array( ‘field_value’ ), ‘fields’ => array( 3, 4 ), ‘limit’ => 1, ) );

    2. David Smith
      David Smith Staff August 8, 2016 at 2:58 pm

      Yes, this is possible by limiting the “field_value” and then specifying an array of fields that should act as a “group”. Here’s an example: http://pastie.org/private/ezv84f6crzan12ynbqwlqa

      In your case, you would want to include the email field and the product name field. This way, the limit of “1” means that the combination of a specific email and product can only be submitted once.

    3. Daniel Gutiérrez
      Daniel Gutiérrez August 21, 2016 at 1:06 pm

      David, I just want to thank you again, this function should be a “native” version or an official addon (I even suggested it to support staf)f, it is so useful!!! You are saving us lots of headaches and problems. We appreaciate it!

  107. Matthew
    Matthew July 18, 2016 at 7:00 pm

    Hi David,

    I am wondering if this snippet might be massaged to help with what I’m trying to do: We get duplicate form submissions on a couple of our forms – One of which is a job submission form with a front-end file uploader. We receive the first submission, and then a day, two days, three days, four days later, we receive another one, this time without the attached uploaded file. Sometimes this happens many times for the same submission. The friendly folks at GF said to use a no duplicates within the form. The issue is that some of our customers use the form to upload several jobs in a row, and I am worried that if I turn on no duplicates on one of the fields, any subsequent submissions may be flagged and missed.. Can you think of a way to curb the duplicates, but still allow the user to use the form several individual times in the same session? Sorry if this seems complicated or off-piste from what this snippet is for.. Just trying to find a solution. Thanks for any insight in advance!

    -Matt

    Reply
    1. David Smith
      David Smith Staff August 8, 2016 at 12:36 pm

      Hi Matt, are the duplicates caused by the user deliberately submitting the same information twice?

    2. Matthew
      Matthew August 8, 2016 at 3:51 pm

      Hi David,

      I am not totally sure what is causing the dupes. The form is primarily a front-end uploader, and the ‘attach a file’ field is required. The dupes that come back are the filled out form, but without any file attachments. This is odd to me because I assumed that the form wouldn’t submit unless the required fields were satiated. The folks at Gravity Forms said that it may be that the page is getting refreshed after a submission, but I tested that and couldn’t recreate the issue. It’s all a bit of a mystery.. Any light you might be able to help shine would be awesome.

      Thanks David,

      -Matt

  108. Jd
    Jd July 5, 2016 at 11:22 am

    Hi, I’ve done paste (installing) this snippet and want to limit submit by ip address. I’ve embed my form to my WordPress site. But, I can still submit to the form twice.

    $this->_args = wp_parse_args( $args, array( ‘form_id’ => 5, ‘limit’ => 1, ‘limit_by’ => ‘ip’, // ‘ip’, ‘user_id’, ‘role’, ’embed_url’, ‘field_value’ ‘time_period’ => 60 * 60 * 24, // integer in seconds or ‘day’, ‘month’, ‘year’ to limit to current day, month, or year respectively ‘limit_message’ => __( ‘Aha, You have completed the survey. Thank you’ ), ‘apply_limit_per_form’ => true, ‘enable_notifications’ => false

    Where did I do wrong? Please advice. Thank you

    Reply
  109. Chris
    Chris July 4, 2016 at 10:13 pm

    Hi, Is it possible to make the limit_message a shortcode from gravity view to display the view when limit is reached? I’d like to define several forms and shortcode combos.

    new GW_Submission_Limit( array( ‘form_id’ => 3, ‘limit_by’ => ‘user_id’, ‘limit’ => 1, ‘time_period’ => false , // forever! ‘limit_message’ => ‘[gravityview id=”398″]’ ) );

    I see this but not sure what I’d need to change there or if. function pre_render( $form ) {

        if( ! $this->is_applicable_form( $form ) || ! $this->is_limit_reached( $form['id'] ) ) {
            return $form;
        }
    

    ( GFFormDisplay::$submission, $form[‘id’] );

        $submission_info = rgar
        // if no submission, hide form
        // if submission and not valid, hide form
        // unless 'field_value' limiter is applied
        if( ( ! $submission_info || ! rgar( $submission_info, 'is_valid' ) ) && ! $this->is_limited_by_field_value() ) {
            add_filter( 'gform_get_form_filter_' . $form['id'], create_function( '', 'return \'<div class="limit-message">' . $this->_args['limit_message'] . '</div>\';' ) );
        }
    
        return $form;
    
    }
    
    Reply
    1. David Smith
      David Smith Staff July 15, 2016 at 9:04 am

      Hi Chris, are you just looking for shortcode support for the “limit_message” property?

  110. Robert de Leeuw
    Robert de Leeuw June 23, 2016 at 10:43 am

    Hi David,

    Thanks again a great and wonderful snippet. Is it somehow possible to limit the submission on 2 variables? I want to limit the combination of field ID 1 and field ID 2. For example, I only want 1 submission of fieldID1=1 and fieldID2=1.

    Trying to make a little more sense with another example. Field ID 1 is “name” and field ID 2 is “high score”. Now I want to limit the combination no duplicates (so just 1 submission of “Robert” and high score “10”).

    Does that make sense?

    Thanks! Robert

    Reply
    1. David Smith
      David Smith Staff June 30, 2016 at 8:53 am

      Yep and this is supported. You can call this limiting by a field group:

      new GW_Submission_Limit( array( ‘form_id’ => 327, ‘limit_by’ => array( ‘field_value’ ), ‘fields’ => array( 1, 2 ), ‘limit’ => 1, ‘time_period’ => false ) );

    1. David Smith
      David Smith Staff June 30, 2016 at 8:53 am

      This is supported. Set the “enable_notifications” parameter to true. You will find a new notification event when creating a new form notification for this form.

  111. ML
    ML June 4, 2016 at 3:54 pm

    Looks promising, as soon as I paste the code, at the end of my theme’s config file, it crashes the site. I tried modifying as instructed (form id, limit_by ip, etc). Any thoughts? Do I have to purchase perks for this to work?

    Reply
    1. ML
      ML June 6, 2016 at 2:43 pm

      Q: In testing, I locked my self out for the day usin ip settings. Where is this being logged? how can I remove a certain IP from the list? Thanks

  112. vlo
    vlo May 31, 2016 at 8:24 am

    new GW_Submission_Limit( array( ‘form_id’ => 86, ‘limit’ => 1, ) );

    I would like to limit several forms:

    ‘form_id’ => 86,77,63,102,

    doesn’t work somehow. any idea?

    Reply
  113. vlo
    vlo May 31, 2016 at 7:40 am

    Basic Usage

    new GW_Submission_Limit( array( ‘form_id’ => 1, ‘limit’ => 1, ‘limit_message’ => ‘Aha! You have been limited.’ ) );

    Using that makes the form disappear after submission. The “limit_message” does not show up :( Any idea?

    Reply
  114. nathan
    nathan May 29, 2016 at 11:10 pm

    Wow – I’m about to play with this… I’m creating a premium listing site where I want to limit the number of businesses in an area to be noncompeting. I basically want to calculate a 50-100mile radius from the business and limit the submissions to only one business , in x category, in x mile radius… Say for instances user is filling out a listing and they type their name, select category , and then they select option for how big a nocompete radius they want to purchase i.e., 25miles , 50miles, 100miles… then the next submitter who tries to purchase a listing who tries to submit a listing inside this radius with same category would get error message saying sorry – your area is locked. Please click here to receive notification when area is available.

    I know this is a very detailed request but I wonder if i can acheive something similar but not exact by using the above snippet. I’m not sure how to best limit submission by radius but wonder if there might be an easier way…

    Reply
  115. Joe
    Joe May 18, 2016 at 7:58 am

    Hi David,

    Bit of an odd one but hoping you can help. :)

    Do you think it would be possible to use the above code to limit based on two fields? One of the fields being a date field.

    We are selling tickets to an event and we have a limited type of each on specific days. E.g. we have 10 Standard Tickets, 20 Premium Tickets for each day shown in a datepicker.

    We cannot use a stock based system as the dates could be any date in the future so this field has a great deal of permutations.

    Reply
    1. Joe
      Joe May 18, 2016 at 9:35 am

      Thank you so much for the point but sorry I am being dense. Am unsure how to apply this to our form! :)

      We have a dropdown (ID – 7) and a datepicker (ID – 6).

      A specific option in the dropdown needs to be limited combined with the dates. All other options are unlimited.

    2. Joe Mallion
      Joe Mallion May 23, 2016 at 9:25 am

      Sorry to keep on about this one but the issue is we do not have a quantity field so have nothing to put in the field_id column. Each submission of the form is 1 ticket. So in this case can I create a hidden field with the value of 1?

    3. David Smith
      David Smith Staff May 24, 2016 at 8:57 am

      Hi Joe, yup, that’s right. Add a Hidden field to act as your quantity field.

    4. Joe Mallion
      Joe Mallion May 24, 2016 at 9:42 am

      Am so sorry to keep on, but it is only one of the options in the dropdown that I want to limit the rest can be unlimited. Guessing that is one step too far? :)

  116. Christopher
    Christopher May 12, 2016 at 6:57 am

    Hello,

    On a multisite installation how can exclude super admin from “Limit by Role” limitations?

    Thanks!

    Reply
  117. Emilien
    Emilien May 12, 2016 at 4:25 am

    Hi and thank you for your work on this great snippet!

    I’d have two questions: 1/ is it possible to have a time period defined by two dates instead of a length? 2/ is it possible to insert $variables when configuring the snippet?

    Thank you in advance for your answers and have a great day, Emilien

    Reply
    1. David Smith
      David Smith Staff May 18, 2016 at 10:01 am

      It is not currently possible to set the time period between to dates. Could you elaborate on #2? What do you mean by $variables?

  118. Emilien
    Emilien May 11, 2016 at 8:04 am

    Hi and thank you very much for this snippet! I’m having trouble customizing some configuration options. I’d need to use variables to define ‘time_period’ and ‘limit’. Here’s where I currently am:

    • I have a custom plugin with 2 functions : the first one returns a number of current subscriptions my users have to a product, the second one returns a time interval (difference between next_payment_date and last_payment_date)

    • my purpose is to limit the number of forms my users can submit, per their subscription time period and based on the amount they are charged

    • my problem is I can’t get the snippet to work if I set things like this:

    configuration

    new GW_Submission_Limit( array( ‘form_id’ => 1, ‘limit_by’ => ‘user_id’, ‘time_period’ => second_function(), ‘limit’ => first_function(), ‘limit_message’ => ‘You have reached the maximum number of submissions your subscription offers’ ) );

    • those two functions return two variable : $nb and $length. I can’t get the snippet to work if I set things like this either:

    configuration

    new GW_Submission_Limit( array( ‘form_id’ => 1, ‘limit_by’ => ‘user_id’, ‘time_period’ => $length, ‘limit’ => $nb, ‘limit_message’ => ‘You have reached the maximum number of submissions your subscription offers’ ) );

    • Using WP Debug I either get “undefined function error” or “undefined variable error”… I guess this is a syntax problem but I’m not sure how to solve this.

    Thank you so much in advance for your help, have a great day, Emilien

    Reply
    1. David Smith
      David Smith Staff May 24, 2016 at 9:22 am

      I would actually expect that to work… Are your functions defined above the snippet?

  119. Bob
    Bob May 10, 2016 at 5:03 am

    Hi David,

    Thanks for all the code/snippets/advice that you offer – amazing stuff.

    Feels cheeky asking but I wondered if there was any simple way to make the time period conditional. In my situation I would like to check the user’s login info to alter the time period.

    I did notice some pastie code that allowed you to check a custom field, so was thinking I could store the time period as user meta and do it that way, but I wondered if there was a way to have conditional code inside the arguments. When I tried I got error messages regarding if statements.

    Thanks again – if too ‘niche’ then no worries,

    Bob

    Reply
    1. David Smith
      David Smith Staff May 18, 2016 at 12:21 pm

      Hi Bob, it is possible but not without additional custom code. You would need to override the validate() method to check if your condition was met before running the limit-based validation.

  120. Steve
    Steve May 4, 2016 at 5:13 pm

    Hey there,

    Very useful snippet, Is there a way to limit per week? That’s the time frame I’m needing but seems to be the only one not supported!

    Thanks, Steve

    Reply
    1. David Smith
      David Smith Staff May 24, 2016 at 9:06 am

      Hi Steve, the snippet has been updated support limiting per week. Using “week” or “per_week” as the time period.

  121. David
    David April 29, 2016 at 6:08 pm

    Hi! The counter for Limit by Role works perfect, but if I update some part of the theme (functions.php, template.php, etc) the counter no longer functions properly and the message “Aha! You have been limited” not appears. I have to delete all entries and create them again and then the counter works correctly and the message “Aha! You have been limited” appears. Where is the error for the meter to function properly? Thanks!

    Regards, David

    Reply
    1. David Smith
      David Smith Staff April 29, 2016 at 10:04 pm

      If you’re overwriting the snippet (as in, it no longer exists in your code), you would need to copy and paste the snippet back into your theme’s functions.php file. If you’re having issues where updating any theme file causes the snippet to break, there is some other conflict at play.

  122. Alex
    Alex April 22, 2016 at 10:08 am

    Hi! Is it possible to limit the submission for a specific date, entered in the form? I want users not o be able to submit lets say more than 5 per date. The will choose the date from the form.

    Reply
  123. David
    David April 20, 2016 at 7:29 pm

    Cant seem to get this to work, no matter what I do!

    Trying to limit several forms by user id to once every six months. my code is the following: [quote] new GW_Submission_Limit( array( ‘form_id’ => array(‘1′,’2′,’3’ ‘limit’ => 1, ‘limit_by’ => ‘user_id’, ”time_period’ => 15778463, //six months in seconds ‘limit_message’ => ‘You already filled out this application form! Please visit the <a href=”/biuintl/portal>Applicant Portal to continue the application process. If you believe you are seeing this message in error, please contact test@email.com‘ ) );

    Any suggestions? This site is supposed to go live in two days :/

    Reply
  124. Armando
    Armando March 29, 2016 at 7:26 pm

    Thank you for this, it works like a charm. I was wondering if I can retrieve a value in the array in a page template? For example, I would like to retrieve the ‘limit’ value and place it in a variable in a page template.

    For example, in my page template:

    $attempts = GW_Submission_Limit =>limit or something similar.

    Thanks again!

    Reply
    1. Armando
      Armando March 29, 2016 at 9:33 pm

      I appreciate your reply! My goal is to retrieve the value that is set in the ‘limit’ from the array in my page template.

      What I am trying to do is basically set a conditional that if limit is = 1 then do something.

      So in my page template:

      $attempts = GW_Submission_Limit =>limit // where I need help :)

      if($attempts = 1){ //my code }else{ //my other code }

      The $attempts value is not coming from a custom field but rather from the value I set in my functions file for ‘limit’.

      Thanks again!

    2. David Smith
      David Smith Staff March 30, 2016 at 8:01 am

      The actual submission count is buried in the is_limit_reached() function. If you just want to check if the limit is reached though you can call