DescriptionUsageParametersExamples1. Use the same message for all fields.2. Use the fields custom validation message.PlacementSource Code
Description
This filter is executed when a form fails the duplicate field validation, before the validation message is displayed. Use this filter to change the the message that is displayed when a field fails the duplicate value validation.
Usage
The following would apply to all fields using the no duplicates feature on all forms.
1add_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)
1add_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.
Examples
1. Use the same message for all fields.
This changes the default no duplicates validation message.
1234add_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.';}
2. Use the fields custom validation message.
This example uses the fields custom validation message as the no duplicates validation message.
1234add_filter( 'gform_duplicate_message', function ( $message, $form, $field ) { return empty( $field->errorMessage ) ? $message : $field->errorMessage;}, 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
1gf_apply_filters( 'gform_duplicate_message', $form['id'], $default_message, $form, $field, $value )
This filter is located in GFFormDisplay::validate() in form_display.php