Post

Prevent duplicate form submissions gravity forms

Below are some methods you can use to prevent duplicate form entries though your gravity forms

Disable Ajax form submissions

If you don’t know the cause of the duplicate entries. One of the first things to try is to disable the Ajax form submissions and just use a static thank you page confirmation. If Ajax is the cause then fixing this issue is outside the scope of this tutorial but at least you have narrowed it down.

Enable no duplicates

Gravity forms has a built in option in the form settings for no duplicates. The requirements for this powerful feature is a field within the form that takes a unique value. Like an invoice number which would be unique.

Create your own unique id hidden field

If you’re form doesn’t have a field that takes a unique value the you can just create your own.

  • Add the following snippet your functions.php file
  • Create a hidden field on your form
  • Update the form-id and field-id in the below snippet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
add_filter("gform_field_value_uuid", "get_unique");
function get_unique(){
    $prefix = "SLP2017-"; // update the prefix here
    do {
        $unique = mt_rand();
        $unique = substr($unique, 0, 8);
        $unique = $prefix . $unique;
    } while (!check_unique($unique));
    return $unique;
}
function check_unique($unique) {
    global $wpdb;
    $table = $wpdb->prefix . 'rg_lead_detail';
    $form_id = 3; // update to the form ID your unique id field belongs to
    $field_id = 7; // update to the field ID your unique id is being prepopulated in
    $result = $wpdb->get_var("SELECT value FROM $table WHERE form_id = '$form_id' AND field_number = '$field_id' AND value = '$unique'");
    if(empty($result))
        return true;
    return false;
}

Stop Gravity Forms Duplicate Submissions and Notifications generate unique id

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.