gform_required_legend

Description

The gform_required_legend filter enables the legend displayed at the bottom of the form header, which explains how required fields are indicated, to be overridden.

Note that this filter has no effect when the “Required Field Indicator” is set to “Text: (Required)”. With that setting, the text (Required) is added to all required fields, and no legend is output.

Usage

add_filter( 'gform_required_legend', 'your_function_name', 10, 2 );

You can also specify this per form by adding the form id after the filter name.

add_filter( 'gform_required_legend_6', 'your_function_name', 10, 2 );

Parameters

  • $legend string
    The required indicator legend.
  • $form Form Object
    The current form object.

Examples

1. Use a custom legend

add_filter( 'gform_required_legend', function( $legend, $form ) {
    return 'your custom legend here';
}, 10, 2 );

2. Empty legend

add_filter( 'gform_required_legend', '__return_empty_string' );

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 v2.5.

Source Code

This filter is located in GFFormDisplay::get_form() in form_display.php.