bookmark_bordergform_is_duplicate

Description

This filter is executed during the validation of fields marked with the “No Duplicates” rule. Use this hook to specify a custom duplicate validation logic.

Usage

The following would apply to all forms:

add_filter( 'gform_is_duplicate', 'your_function_name', 10, 4 );

To target a specific form append the form id to the hook name. (Format: gform_is_duplicate_FORMID)

add_filter( 'gform_is_duplicate_5', 'your_function_name', 10, 4 );

Parameters

  • $count integer

    The number of duplicate entries. Filtering this value to 0 means there are no duplicates.

  • $form_id integer

    The current form’s id.

  • $field Field Object

    The current field being validated

  • $value string

    The value of the current field

Examples

1. Check if email already registered

This example checks to see if the email address is already in use. If so, consider the email a duplicate and return a count of 1; otherwise return a count of 0.

add_filter( 'gform_is_duplicate', 'noDuplicateEMails', 10, 4 );
function noDuplicateEMails( $count, $form_id, $field, $value ) {
   if ( $field->type == 'email' && get_user_by( 'email', $value ) ) {
     return 1;
   } else {
     return 0;
   }
}

Source Code

This filter is located in GFFormsModel::is_duplicate() in forms_model.php