The gform_required_legend filter enables you to override the legend displayed at the bottom of the form header, which explains how required fields are indicated.
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.
More information
See Gravity Forms Docs: gform_required_legend
Note: Place the code examples in the functions.php file of your active theme or a custom functions plugin.
Examples
Use a custom legend
Change the required legend text with your custom text.
add_filter('gform_required_legend', function($legend, $form) {
return 'your custom legend here';
}, 10, 2);
Empty legend
Remove the required legend completely.
add_filter('gform_required_legend', '__return_empty_string');
Custom legend for a specific form
Change the required legend text for a specific form with ID 6.
add_filter('gform_required_legend_6', function($legend, $form) {
return 'custom legend for form 6';
}, 10, 2);
Include form title in the legend
Add the form title to the required legend.
add_filter('gform_required_legend', function($legend, $form) {
return 'Fields marked with an * are required for ' . $form['title'];
}, 10, 2);
Conditional legend based on form ID
Change the required legend text based on form ID.
add_filter('gform_required_legend', function($legend, $form) {
if ($form['id'] == 6) {
return 'custom legend for form 6';
} elseif ($form['id'] == 7) {
return 'custom legend for form 7';
}
return $legend;
}, 10, 2);