Halloween Sale 15% off Ends in See the plans
PHP

One WPForms Submission per Email per Day

Stops the same email address from submitting a WPForms form more than once in 24 hours, useful for giveaways and quote requests, even in WPForms Lite.

Don’t have WPIDE yet? Install it on your site

Code

$wpide_wpf_daily_forms = array(); // Form IDs to protect, e.g. array( 1 ).
$wpide_wpf_daily_hours = 24;

add_action( 'wpforms_process_validate_email', function ( $field_id, $field_submit, $form_data ) use ( $wpide_wpf_daily_forms ) {
    if ( ! in_array( (int) $form_data['id'], array_map( 'intval', $wpide_wpf_daily_forms ), true ) ) {
        return;
    }

    $email = strtolower( trim( is_array( $field_submit ) ? (string) reset( $field_submit ) : (string) $field_submit ) );

    if ( is_email( $email ) && get_transient( 'wpide_wpf_once_' . md5( $form_data['id'] . '|' . $email ) ) ) {
        $process = method_exists( wpforms(), 'obj' ) ? wpforms()->obj( 'process' ) : wpforms()->process;
        $process->errors[ $form_data['id'] ][ $field_id ] = 'This email address has already been used today.';
    }
}, 10, 3 );

add_action( 'wpforms_process_complete', function ( $fields, $entry, $form_data ) use ( $wpide_wpf_daily_forms, $wpide_wpf_daily_hours ) {
    if ( ! in_array( (int) $form_data['id'], array_map( 'intval', $wpide_wpf_daily_forms ), true ) ) {
        return;
    }

    foreach ( (array) $fields as $field ) {
        if ( isset( $field['type'] ) && 'email' === $field['type'] && is_email( $field['value'] ) ) {
            set_transient( 'wpide_wpf_once_' . md5( $form_data['id'] . '|' . strtolower( trim( $field['value'] ) ) ), 1, $wpide_wpf_daily_hours * HOUR_IN_SECONDS );
        }
    }
}, 10, 3 );

Notes

Only the forms listed at the top are checked; addresses are kept only as hashes in transients that expire after the waiting period.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.