# Limit Gravity Forms Entries per IP Address

> Stops a visitor from sending more than a few Gravity Forms entries per hour from the same IP address, with a polite message, to block flooding and repeat spam.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: gravity-forms, spam, rate-limit
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gf-rate-limit-ip/

## Code

```php
$wpide_gf_max_entries = 3;       // Entries allowed per IP...
$wpide_gf_window      = '1 hour'; // ...within this period.
$wpide_gf_limit_forms = array(); // Form IDs to limit; empty = all.

add_filter( 'gform_validation', function ( $validation ) use ( $wpide_gf_max_entries, $wpide_gf_window, $wpide_gf_limit_forms ) {
    $form = $validation['form'];

    if ( ! $validation['is_valid'] || ( $wpide_gf_limit_forms && ! in_array( (int) $form['id'], array_map( 'intval', $wpide_gf_limit_forms ), true ) ) ) {
        return $validation;
    }

    $count = GFAPI::count_entries( $wpide_gf_limit_forms ? (int) $form['id'] : 0, array(
        'status'        => 'active',
        'start_date'    => wp_date( 'Y-m-d H:i:s', strtotime( '-' . $wpide_gf_window ) ),
        'field_filters' => array( array( 'key' => 'ip', 'value' => GFFormsModel::get_ip() ) ),
    ) );

    if ( $count >= $wpide_gf_max_entries ) {
        $validation['is_valid'] = false;
        foreach ( $form['fields'] as $field ) {
            if ( ! in_array( $field->type, array( 'hidden', 'html', 'section', 'page' ), true ) ) {
                $field->failed_validation  = true;
                $field->validation_message = 'You have sent several messages recently. Please try again later.';
                break;
            }
        }
        $validation['form'] = $form;
    }

    return $validation;
} );
```

## Notes

Counts entries already stored for that IP across all forms; set a form ID in the list to limit only specific forms.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Limit Gravity Forms Entries per IP Address" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
