• Resolved tomis69

    (@tomis69)


    Hello there,

    I have 2 forms (IDs: 1618 and 1636). I found php code for mu-plugin and all works fine but i can not put different amount of submissions limiting up to 5 for every 24 hours only for ID 1636. Can you help me with that please? Please see used code below:

    <?php

    add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ) {
    // Add your form IDs here.
    $form_ids = array( 1618 );
    // 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);

    add_filter( 'forminator_custom_form_invalid_form_message', 'wpmudev_invalid_form_error', 10, 2 );
    function wpmudev_invalid_form_error( $invalid_form_message, $form_id ){
    if( $form_id != 1618 ) {
    return $invalid_form_message;
    }
    $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 ) {
    $invalid_form_message = __( 'You cannot submit more than 1 time within 24 hours.', 'forminator' );
    }
    }
    }
    return $invalid_form_message;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @tomis69

    I hope you’re well today!

    I’m afraid we cannot help you with this. You’re absolutely welcome to use and/or build upon any existing custom code that we shared in the past but we do not provide any kind of custom development at any level currently.

    Kind regards,
    Adam

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @tomis69,

    Since we haven’t heard from you for a while. I’ll mark this thread as resolved for now. Please feel free to re-open this thread if you need any further assistance.

    Best Regards
    Nithin

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Limited form submissions’ is closed to new replies.