PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Custom validation for is_duplicate

  1. Hello.

    I have a task. User enter in the form a key and address. I have to check the key of user. If the key is in database, we accept form submission only once. If the key is not in DB, we show error message "unvalid key". Before running the form I will fill the entries database with the list of valid keys.

    I suppose it is good idea to use is_duplicate filter for checking the key, but I have no idea how to make the validation work in the way I want.

    Should be something like this:

    add_action('gform_is_duplicate_1', 'check_key', 10, 4);
    function check_key($count, $form_id, $field, $value) {
    // If there is one entry of such a key, accept form submission and add one more entry with this key and address
    //(would be great to update entry, instead of adding one more, but I guess GF doesn't have such a functionality)
        if ( $count == 1  )  {
           add_filter("gform_field_validation_1_2", "custom_validation", 10, 4);
           function custom_validation($result, $value, $form, $field) {
              $result["is_valid"] = true;
           }
        }
        else {
             $error_message="Invalid key!";
        }
    }

    Could you please help me with the code?

    Posted 12 years ago on Thursday October 13, 2011 | Permalink