Limit number of entries in Fluent Forms

tdrayson

A member in the Fluent Forms community wanted a way to limit each user to a max of 25 entries per form.

Below is a snippet you can use to limit based on the user’s email. Place this in functions.php or your code snippet plugin.

PHP

        <?php

add_filter("fluentform_validate_input_item_input_email", function ($error, $field, $formData, $fields, $form) {
    
    $my_form_id = 1; // Replace with your Form ID
    $max_entries = 25; // Replace with max number of allowed entries

    if ($form->id != $my_form_id) {
        return $error;
    }

    $email = $formData['email']; // This is the name of your email field
    
    if (empty($email)) {
        return $error;
    }
    
    $max_entries = $max_entries + 1;
    
    $formApi = fluentFormApi("forms")->entryInstance($formId = $my_form_id);
    $atts = [
        "per_page" => $max_entries,
        "search" => $email,
        "sort_by" => "DESC",
        "entry_type" => "all",
    ];
    
    $entries = $formApi->entries($atts, $includeFormats = false);
    
    if( $entries['total'] >= $max_entries){
        return ['You have reached the entry limit'];
    }
    
    return $error;
    
},10,5);
      
Copy

👋🏻 Weekly Tutorial Digest

I send out a weekly newsletter with links to new tutorials written in the last week, you can subscribe below.

Newsletter

🔒I won't send you spam, I promise