November 10, 2018: Updated to work with Gravity Forms 2.3+. Special thanks to Daniel Kelly.
How do I get started?
- Gravity Forms v1.8 is required to use this snippet.
- Copy and paste the snippet into your theme’s functions.php file.
- Modify the “Configuration” portion of the snippet (at the very bottom of the code) to meet your needs. Full usage instructions are below.
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 ) );
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! ) );
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
falseor do not include this parameter at all. If you would like to limit multiple forms, pass the value as an array of form IDs.
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
The period of time to which the
limitapplies. The default time period is one day. In any 24 hour period, if the user reaches the
limitthey 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
60would 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_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
The message which should be displayed to the user once they have reached the specified submission limit.
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.