Quantcast
Viewing all articles
Browse latest Browse all 196

Better Limit Submission Per Time Period by User or IP

View this code snippet on GitHub.

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.

View this code snippet on GitHub.

Apply to ALL Forms

Apply a submission limit per 24 hours period to ALL forms.

View this code snippet on GitHub.

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.

View this code snippet on GitHub.

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.

View this code snippet on GitHub.

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.

View this code snippet on GitHub.

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.

View this code snippet on GitHub.

Parameters

  • form_id

    The form ID of the form 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.

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

Viewing all articles
Browse latest Browse all 196

Trending Articles