Description
The gform_field_sidebar_messages filter allows the field sidebar messages to be modified in the form editor.
Usage
add_filter( 'gform_field_sidebar_messages', 'your_function_name', 10, 2 );
Parameters
| Parameter | Type | Description |
|---|---|---|
| $messages | array|string | The field sidebar messages. Can be an array with type, content, and icon_helper_text keys, or a simple string. Strings default to the error style. Return the existing messages unchanged to preserve them. |
| $field | GF_Field | The current field object. |
Examples
Add a notice to all fields.
The following example adds a notice style message to all fields except the submit button. If a field already has messages, the existing messages are preserved.
add_filter( 'gform_field_sidebar_messages', function ( $messages, $field ) {
if ( $field->type === 'submit' ) {
return $messages;
}
if ( ! empty( $messages ) ) {
return $messages;
}
$custom_message = array(
'type' => 'notice',
'content' => 'This message is added to all fields except submit, but will not show when a field has an existing message.',
'icon_helper_text' => 'This is the tooltip info in the compact view.',
);
return $custom_message;
}, 10, 2 );
Add an error message to Single Line Text fields.
The following example adds a simple string error style message to single line text fields only.
add_filter( 'gform_field_sidebar_messages', function ( $messages, $field ) {
if ( $field->type !== 'text' ) {
return $messages;
}
return 'Simple string error message appears only on single line text fields.';
}, 10, 2 );
Overwrite all field messages.
The following example overwrites any existing field messages on all fields except the submit button.
add_filter( 'gform_field_sidebar_messages', function ( $messages, $field ) {
if ( $field->type === 'submit' ) {
return $messages;
}
return 'Simple string error message, overwriting all existing field messages';
}, 10, 2 );
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Since
This filter was added in Gravity Forms 2.9.29.
Source Code
This filter is located in class-gf-field.php.