Using Gravity Forms ‘gform_duplicate_message’ PHP filter

The gform_duplicate_message filter allows you to modify the message displayed when a field fails duplicate value validation in Gravity Forms.

Usage

To apply this filter to all fields using the “No Duplicates” feature on all forms:

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

To target a specific form, append the form ID to the hook name (format: gform_duplicate_message_FORMID):

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

Parameters

  • $message (string): The validation message to be filtered.
  • $form (Form Object): The current form.
  • $field (Field Object): Current Field object.
  • $value (string): The field value being validated.

More information

See Gravity Forms Docs: gform_duplicate_message

Examples

Use the same message for all fields

Change the default “No Duplicates” validation message:

add_filter('gform_duplicate_message', 'change_message', 10, 2);

function change_message($message, $form) {
  return 'This field failed the duplicate value validation. Please enter a different value.';
}

Use the field’s custom validation message

Use the field’s custom validation message as the “No Duplicates” validation message:

add_filter('gform_duplicate_message', function($message, $form, $field) {
  return empty($field->errorMessage) ? $message : $field->errorMessage;
}, 10, 3);

Custom message for a specific form

Change the duplicate message for a specific form (Form ID: 5):

add_filter('gform_duplicate_message_5', 'change_message_for_form_5', 10, 4);

function change_message_for_form_5($message, $form, $field, $value) {
  return 'Duplicate value detected. Please enter a unique value.';
}

Custom message for a specific field

Change the duplicate message for a specific field (Field ID: 3):

add_filter('gform_duplicate_message', 'change_message_for_field_3', 10, 4);

function change_message_for_field_3($message, $form, $field, $value) {
  if ($field->id == 3) {
    return 'This value is already in use. Please try a different one.';
  }
  return $message;
}

Custom message based on field type

Change the duplicate message for a specific field type (e.g., Email fields):

add_filter('gform_duplicate_message', 'change_message_for_email_fields', 10, 4);

function change_message_for_email_fields($message, $form, $field, $value) {
  if ($field->type == 'email') {
    return 'This email address is already in use. Please try a different one.';
  }
  return $message;
}

Note: Place the code in the functions.php file of your active theme.