• Resolved ilan76

    (@ilan76)


    Hi,

    How can I restrict form submissions by daily limit, for example up to 10 per day?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Zafer – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @ilan76,

    I hope you are doing well today!

    This issue has been flagged to our SLS (Second Line Support) Team so that they can dig into this further. We will post an update here as soon as more information is available.

    Please keep in mind that our SLS Team deals with more complicated issues, so it may take a little longer for them to reply here.

    Thank you for your patience while we look into this further.

    Kind regards,
    Zafer

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @ilan76,

    Could you please try this snippet and see how it goes?

    <?php
    
    add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ) {
        // Add your form IDs here.
        $form_ids = array( 6 );
        // Change this to the message that you want to show.
        $message = 'You cannot submit more than 10 times within a day.';
        if ( in_array( intval( $form_id ), $form_ids, true ) ) {
            $last_entry = wpmudev_get_last_few_entries( $form_id );
            if ( $last_entry ) {
                $submit_errors[]['submit'] = $message;
                $GLOBALS['form_error'] = true;
            } else {
                $GLOBALS['form_error'] = false;
            }
        }
        return $submit_errors;
    },15,3);
    
    function wpmudev_get_last_few_entries( $form_id ){
        global $wpdb;
        $entry_table_name   = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY );
        $start_date         = date( 'Y-m-d' ) . ' 00:00:00';
        $end_date           = date( 'Y-m-d' ) . ' 23:59:59';
        $sql                = "SELECT count(*) FROM {$entry_table_name} WHERE form_id = %d AND date_created >= '%s' AND date_created <= '%s'";
        $entry_count        = $wpdb->get_var( $wpdb->prepare( $sql, $form_id, $start_date, $end_date ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
        if ( $entry_count >= 10 ) {
            return true;
        }
        return false;
    }
    
    add_filter( 'forminator_custom_form_invalid_form_message', 'wpmudev_invalid_form_error_response_submit', 10, 2 );
    function wpmudev_invalid_form_error_response_submit( $invalid_form_message, $form_id ){
    	if ( $form_id != 6 ) {
    		return $invalid_form_message;
    	}
    
    	if ( $GLOBALS['form_error'] ) {
    		$invalid_form_message = __( 'You cannot submit more than 10 times within a day.', 'forminator' );
    	}
    
    	return $invalid_form_message;
    }

    You’ll have to change the line in the above code where you notice 6 to your Form ID.

    You can apply the above code as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Please do let us know how that goes.

    Kind Regards,

    Nithin

    Thread Starter ilan76

    (@ilan76)

    Thanks!

    I think this option should be added to form settings.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @ilan76

    We do have plans to add such/similar additional limit options to the plugin. I don’t have ETA but it’s on a list so should be implemented in future.

    Best regards,
    Adam

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Restrict Submissions’ is closed to new replies.