One Gravity Forms Entry per Email Address per Day
Prevents the same email address from submitting a Gravity Forms form more than once in 24 hours, useful for giveaways, sign-ups and quote forms.
Opens WPIDE on
Code
$wpide_gf_daily_forms = array(); // Form IDs to protect, e.g. array( 1 ).
$wpide_gf_daily_hours = 24;
add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) use ( $wpide_gf_daily_forms, $wpide_gf_daily_hours ) {
if ( 'email' !== $field->type || ! $result['is_valid'] || ! in_array( (int) $form['id'], array_map( 'intval', $wpide_gf_daily_forms ), true ) ) {
return $result;
}
$email = strtolower( trim( is_array( $value ) ? (string) reset( $value ) : (string) $value ) );
if ( ! is_email( $email ) ) {
return $result;
}
$count = GFAPI::count_entries( (int) $form['id'], array(
'status' => 'active',
'start_date' => wp_date( 'Y-m-d H:i:s', time() - $wpide_gf_daily_hours * HOUR_IN_SECONDS ),
'field_filters' => array( array( 'key' => (string) $field->id, 'value' => $email ) ),
) );
if ( $count > 0 ) {
$result['is_valid'] = false;
$result['message'] = 'This email address has already been used today.';
}
return $result;
}, 10, 4 );
Notes
Only checks the forms listed at the top, using each form's first email field; Gravity Forms' own "No Duplicates" setting blocks repeats forever instead.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.