Limiting user submissions

One submission per IP address

Add the following code to the WordPress theme functions.php file (or create a plugin for it).

12
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
add_filter('quform_pre_process_1', function (array $result, Quform_Form $form) {    global $wpdb;
 
    $query = $wpdb->prepare(
        "SELECT COUNT(*) FROM {$wpdb->prefix}quform_entries WHERE form_id = %d AND ip = %s;",
        $form->getId(),
        Quform::getClientIp()
    );
 
    if ($wpdb->get_var($query) > 0) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => 'Only one submission is allowed'
            )
        );
    }
 
    return $result;
}, 10, 2);
add_filter('quform_pre_process_1', function (array $result, Quform_Form $form) {
    global $wpdb;

    $query = $wpdb->prepare(
        "SELECT COUNT(*) FROM {$wpdb->prefix}quform_entries WHERE form_id = %d AND ip = %s;",
        $form->getId(),
        Quform::getClientIp()
    );

    if ($wpdb->get_var($query) > 0) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => 'Only one submission is allowed'
            )
        );
    }

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
12
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
add_filter('quform_pre_process', function (array $result, Quform_Form $form) {    global $wpdb;
 
    $query = $wpdb->prepare(
        "SELECT COUNT(*) FROM {$wpdb->prefix}quform_entries WHERE form_id = %d AND ip = %s;",
        $form->getId(),
        Quform::getClientIp()
    );
 
    if ($wpdb->get_var($query) > 0) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => 'Only one submission is allowed'
            )
        );
    }
 
    return $result;
}, 10, 2);
add_filter('quform_pre_process', function (array $result, Quform_Form $form) {
    global $wpdb;

    $query = $wpdb->prepare(
        "SELECT COUNT(*) FROM {$wpdb->prefix}quform_entries WHERE form_id = %d AND ip = %s;",
        $form->getId(),
        Quform::getClientIp()
    );

    if ($wpdb->get_var($query) > 0) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => 'Only one submission is allowed'
            )
        );
    }

    return $result;
}, 10, 2);

One submission per user account (for logged in users)

Add the following code to the WordPress theme functions.php file (or create a plugin for it).

12
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
add_filter('quform_pre_process_1', function (array $result, Quform_Form $form) {    global $wpdb;
 
    $query = $wpdb->prepare(
        "SELECT COUNT(*) FROM {$wpdb->prefix}quform_entries WHERE form_id = %d AND created_by = %d;",
        $form->getId(),
        get_current_user_id()
    );
 
    if ($wpdb->get_var($query) > 0) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => 'Only one submission is allowed'
            )
        );
    }
 
    return $result;
}, 10, 2);
add_filter('quform_pre_process_1', function (array $result, Quform_Form $form) {
    global $wpdb;

    $query = $wpdb->prepare(
        "SELECT COUNT(*) FROM {$wpdb->prefix}quform_entries WHERE form_id = %d AND created_by = %d;",
        $form->getId(),
        get_current_user_id()
    );

    if ($wpdb->get_var($query) > 0) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => 'Only one submission is allowed'
            )
        );
    }

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
12
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
add_filter('quform_pre_process', function (array $result, Quform_Form $form) {    global $wpdb;
 
    $query = $wpdb->prepare(
        "SELECT COUNT(*) FROM {$wpdb->prefix}quform_entries WHERE form_id = %d AND created_by = %d;",
        $form->getId(),
        get_current_user_id()
    );
 
    if ($wpdb->get_var($query) > 0) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => 'Only one submission is allowed'
            )
        );
    }
 
    return $result;
}, 10, 2);
add_filter('quform_pre_process', function (array $result, Quform_Form $form) {
    global $wpdb;

    $query = $wpdb->prepare(
        "SELECT COUNT(*) FROM {$wpdb->prefix}quform_entries WHERE form_id = %d AND created_by = %d;",
        $form->getId(),
        get_current_user_id()
    );

    if ($wpdb->get_var($query) > 0) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => 'Only one submission is allowed'
            )
        );
    }

    return $result;
}, 10, 2);
Be inspired. © 2019 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy