# Reject Gravity Forms Submitted Too Quickly

> Adds a signed time stamp to each Gravity Forms form and marks entries sent within a few seconds of the page loading as spam, which catches bots that fill forms instantly.

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

## Code

```php
$wpide_gf_min_seconds = 4; // Minimum seconds between page load and submit.

add_filter( 'gform_form_tag', function ( $tag, $form ) {
    $time = (string) time();
    $tag .= '<input type="hidden" name="wpide_gf_ts" value="' . esc_attr( $time . '.' . wp_hash( 'gf-ts-' . $time ) ) . '">';

    return $tag;
}, 10, 2 );

add_filter( 'gform_entry_is_spam', function ( $is_spam, $form, $entry ) use ( $wpide_gf_min_seconds ) {
    if ( $is_spam ) {
        return $is_spam;
    }

    $stamp = isset( $_POST['wpide_gf_ts'] ) ? sanitize_text_field( wp_unslash( $_POST['wpide_gf_ts'] ) ) : '';
    $parts = explode( '.', $stamp, 2 );
    $valid = 2 === count( $parts ) && ctype_digit( $parts[0] ) && hash_equals( wp_hash( 'gf-ts-' . $parts[0] ), $parts[1] );

    if ( $valid && time() - (int) $parts[0] >= $wpide_gf_min_seconds ) {
        return false;
    }

    if ( method_exists( 'GFCommon', 'set_spam_filter' ) ) {
        GFCommon::set_spam_filter( rgar( $form, 'id' ), 'WPIDE time trap', $valid ? 'Submitted too quickly.' : 'Missing time stamp.' );
    }

    return true;
}, 10, 3 );
```

## Notes

Safe with page caching because older stamps always pass; multi-page forms keep the first stamp.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Reject Gravity Forms Submitted Too Quickly" 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/
