One Fluent Forms Submission per Email per Day
Stops the same email address from submitting a Fluent Forms form more than once in 24 hours, useful for giveaways, trials and quote requests.
Opens WPIDE on
Code
$wpide_ff_daily_forms = array(); // Form IDs, e.g. array( 1 ).
$wpide_ff_daily_field = 'email';
$wpide_ff_daily_hours = 24;
$wpide_ff_daily_key = function ( $form_id, $email ) {
return 'wpide_ff_once_' . md5( $form_id . '|' . strtolower( trim( $email ) ) );
};
add_filter( 'fluentform/validation_errors', function ( $errors, $data, $form ) use ( $wpide_ff_daily_forms, $wpide_ff_daily_field, $wpide_ff_daily_key ) {
if ( ! in_array( (int) $form->id, array_map( 'intval', $wpide_ff_daily_forms ), true ) || empty( $data[ $wpide_ff_daily_field ] ) || ! is_string( $data[ $wpide_ff_daily_field ] ) ) {
return $errors;
}
if ( get_transient( $wpide_ff_daily_key( $form->id, $data[ $wpide_ff_daily_field ] ) ) ) {
$errors[ $wpide_ff_daily_field ] = array( 'This email address has already been used today.' );
}
return $errors;
}, 10, 3 );
add_action( 'fluentform/submission_inserted', function ( $entry_id, $data, $form ) use ( $wpide_ff_daily_forms, $wpide_ff_daily_field, $wpide_ff_daily_hours, $wpide_ff_daily_key ) {
if ( in_array( (int) $form->id, array_map( 'intval', $wpide_ff_daily_forms ), true ) && ! empty( $data[ $wpide_ff_daily_field ] ) && is_string( $data[ $wpide_ff_daily_field ] ) ) {
set_transient( $wpide_ff_daily_key( $form->id, $data[ $wpide_ff_daily_field ] ), 1, $wpide_ff_daily_hours * HOUR_IN_SECONDS );
}
}, 10, 3 );
Notes
Checks the forms and email field listed at the top; addresses are stored only as hashes in transients that expire.
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.