PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Limit number of submissions in the time interval

  1. What I want to do:

    I want to limit number of posts users can submit (per usergroup) either:

    • Better: User can't submit the form again until n minutes pass. So users can't spam the blog submitting lots of posts in several minutes.
    • Worse: Users can submit only n forms in 24 hours. At midnight the number of allowed submissions replenish for all users.

    How can I do that with minimum code editing? May be there were some snippets done for that already?
    Thanks.

    Posted 13 years ago on Tuesday March 22, 2011 | Permalink
  2. Is the user going to be a logged in user on the WordPress site or is it going to be based on something like a specific email they use in an email field? How do you distinguish users?

    Posted 13 years ago on Tuesday March 22, 2011 | Permalink
  3. Logged only. As I said I want it to be permission based. So basicly contributors will have the limit and authors either will have much bigger limit or will have none.

    Posted 13 years ago on Wednesday March 23, 2011 | Permalink
  4. This customization would require code. You'd have to use the gform_pre_render hook and write custom code to see if the user has already submitted an entry within the last X days/hours/whatever by querying the entry data.

    Here is the gform_pre_render hook documentation:

    http://www.gravityhelp.com/documentation/page/Gform_pre_render

    Note what you want to do we don't currently have any code samples.

    Posted 13 years ago on Wednesday March 23, 2011 | Permalink
  5. Is there a way to get the time of the last submitted post by a user?

    I can just subtract last post's time from current time and then if it is smaller than predefined ammount - hide the form and display the message? I think it is the most economical way. Is that possible?

    Posted 13 years ago on Friday March 25, 2011 | Permalink
  6. Yes, you'd have to query the entry data. I'll have to get one of our developers to look at this and see what you want to do and come up with a code snippet. This may take some time as customizations such as this are outside the scope of standard support.

    Posted 13 years ago on Friday March 25, 2011 | Permalink
  7. ok! Great

    Posted 13 years ago on Saturday March 26, 2011 | Permalink
  8. Hi Octavian,

    Paste this code into your theme's functions.php file: http://pastie.org/1721866

    Make sure to update the code per the inline instructions. Let me know how this works for you.

    Posted 13 years ago on Sunday March 27, 2011 | Permalink
  9. Wonderful!! thanks a lot!
    I will test that in a while.

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  10. David,

    Is there a way to edit your code to limit the number of submissions by IP instead of user id?

    I've recently had a spammer fill out a form on our site a hundred times in a row.

    Very frustrating.

    Posted 13 years ago on Wednesday August 31, 2011 | Permalink
  11. That code could definitely be customized to do so. But if you aren't comfortable with code you may need to get a developer to assist you.

    Another option is to consider using captcha on your form. Or try the Gravity Forms v1.6 beta release which has built in Akismet anti-spam integration if you have Akismet activated.

    Posted 13 years ago on Wednesday August 31, 2011 | Permalink
  12. Used David's code as an inspiration to write the function/filter necessary to prevent duplicate submissions from the same IP address: https://gist.github.com/1187600

    Posted 13 years ago on Thursday September 1, 2011 | Permalink
  13. Thank you Joachim!

    Posted 13 years ago on Friday September 2, 2011 | Permalink