[Forminator Pro] Limiting form submissions (via IP address) within time period.

I’m wondering if it’s possible to limit the number of responses one can do from a certain IP address to 1 every 24 hours?

I can’t see it in any of the settings so I’m think it’s not at the moment but I’m hoping if not, maybe someone has possible created something to pull it off.

  • Neel Gajjar
    • Staff

    Hello Lawrence,
    how are you doing today?

    I’m really sorry to say that currently there is no such option available out of the box for limiting form submission via IP address within a time frame. But we do have a small code Snippet which can help you to achieve this.

    Our SLS team have made a mu-plugin for you that limits the form submissions for 24hours if they are from the same IP and for the same Form.

    Here is the guide on how to install mu-plugin.
    Please take a FULL backup of the site before adding this mu-plugin.

    1. Create a PHP file with the code attached below. Name the file something like form-limit-ip.php

    2. Navigate to the wp-content folder via FileManager or FTP.

    3. Create a folder called mu-plugins (If not already created) inside wp-content.

    4. Add/upload the file form-limit-ip.php inside the mu-plugins folder. So now the path for the file should be something like this (/wp-content/mu-plugins/form-limit-ip.php)

    You can also follow this detailed guide on how to create mu-plugins
    https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    <?php
    
    add_filter(
    
    'forminator_custom_form_submit_errors',
    
    function( $submit_errors, $form_id, $field_data_array ) {
    
    // Add your form IDs here.
    
    $form_ids = array( 49, 15, 20 );
    
    // Change this to the message that you want to show.
    
    $message = 'You cannot submit more than 1 time within 24 hours.';
    
    if ( in_array( intval( $form_id ), $form_ids, true ) ) {
    
    $user_ip = Forminator_Geo::get_user_ip();
    
    if ( ! empty( $user_ip ) ) {
    
    $last_entry = Forminator_Form_Entry_Model::get_last_entry_by_ip_and_form( $form_id, $user_ip );
    
    if ( ! empty( $last_entry ) ) {
    
    $entry        = Forminator_API::get_entry( $form_id, $last_entry );
    
    $current_time = strtotime( date( 'Y-m-d H:i:s' ) );
    
    $future_time  = strtotime( '+1 day', strtotime( $entry->date_created_sql ) );
    
    if ( $current_time < $future_time ) {
    
    $submit_errors[]['submit'] = $message;
    
    }
    
    }
    
    }
    
    }
    
    return $submit_errors;
    
    },
    
    15,
    
    3
    
    );

    Note :
    You need to edit $form_ids = array( 49, 15, 20 ); with the Id of your forms.
    For eg if you form has ID 250 then it should be something like this $form_ids = array( 250);
    You can add multiple forms as you can see as a comma-separated list. You can also change the $message to show anything you like for a form error.

    Hope this helps.

    Feel free to reply here if you’ve any more questions or concerns.

    Kind Regards,
    Neel Gajjar

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.