How do I allow only 1 form submission per IP address?

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

12
3
4
5
6
7
8
9
10
11
12
13
14
15
1617
18
19
20
21
22
add_filter('quform_pre_validate_1', function (array $result, Quform_Form $form) {    global $wpdb;
    $repository = Quform::getService('repository');
 
    $row = $wpdb->get_row($wpdb->prepare(
        "SELECT * FROM " . $repository->getEntriesTableName() . " WHERE ip = %s AND form_id = %d",
        Quform::getClientIp(),
        $form->getId()
    ), ARRAY_A);
 
    if (is_array($row)) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'content' => 'Only one submission is allowed'            )
        );
    }
 
    return $result;
}, 10, 2);
add_filter('quform_pre_validate_1', function (array $result, Quform_Form $form) {
    global $wpdb;
    $repository = Quform::getService('repository');

    $row = $wpdb->get_row($wpdb->prepare(
        "SELECT * FROM " . $repository->getEntriesTableName() . " WHERE ip = %s AND form_id = %d",
        Quform::getClientIp(),
        $form->getId()
    ), ARRAY_A);

    if (is_array($row)) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'content' => 'Only one submission is allowed'
            )
        );
    }

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
  • On line 16 replace the text Only one submission is allowed with the error message you want to display
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1617
18
19
20
21
22
23
function my_check_submission_ip(array $result, Quform_Form $form) {
    global $wpdb;
    $repository = Quform::getService('repository');
 
    $row = $wpdb->get_row($wpdb->prepare(
        "SELECT * FROM " . $repository->getEntriesTableName() . " WHERE ip = %s AND form_id = %d",
        Quform::getClientIp(),
        $form->getId()
    ), ARRAY_A);
 
    if (is_array($row)) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'content' => 'Only one submission is allowed'            )
        );
    }
 
    return $result;
}
add_filter('quform_pre_validate_1', 'my_check_submission_ip', 10, 2);
function my_check_submission_ip(array $result, Quform_Form $form) {
    global $wpdb;
    $repository = Quform::getService('repository');

    $row = $wpdb->get_row($wpdb->prepare(
        "SELECT * FROM " . $repository->getEntriesTableName() . " WHERE ip = %s AND form_id = %d",
        Quform::getClientIp(),
        $form->getId()
    ), ARRAY_A);

    if (is_array($row)) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'content' => 'Only one submission is allowed'
            )
        );
    }

    return $result;
}
add_filter('quform_pre_validate_1', 'my_check_submission_ip', 10, 2);
  • On line 16 replace the text Only one submission is allowed with the error message you want to display
  • On line 23, replace the number 1 with the form ID
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy