The gform_previous_button filter allows you to modify the markup for the previous button in Gravity Forms.
Usage
To apply the filter to all forms:
add_filter('gform_previous_button', 'my_previous_button_markup', 10, 2);
To apply the filter to a specific form:
add_filter('gform_previous_button_10', 'my_previous_button_markup', 10, 2);
Parameters
- $previous_button (string): The default markup for the previous button.
- $form (Form Object): The current form.
More information
See Gravity Forms Docs: gform_previous_button
Examples
Wrap the previous button in a custom <div>
This example wraps the previous button in a custom <div> with a class for advanced CSS styling.
add_filter('gform_previous_button', 'my_previous_button_markup', 10, 2); function my_previous_button_markup($previous_button, $form) { $previous_button = '<div class="my-custom-class">' . $previous_button . '</div>'; return $previous_button; }
Change the previous button text
This example changes the text of the previous button.
add_filter('gform_previous_button', 'change_previous_button_text', 10, 2); function change_previous_button_text($previous_button, $form) { return '<input type="button" class="button" value="Go Back" onclick="window.history.back();">'; }
Add an icon to the previous button
This example adds an icon to the previous button using Font Awesome.
add_filter('gform_previous_button', 'add_icon_previous_button', 10, 2); function add_icon_previous_button($previous_button, $form) { return '<button class="button"><i class="fas fa-arrow-left"></i> Previous</button>'; }
Hide the previous button on a specific form
This example hides the previous button on a specific form (form ID 5).
add_filter('gform_previous_button_5', 'hide_previous_button', 10, 2); function hide_previous_button($previous_button, $form) { return ''; }
Change the previous button style
This example changes the style of the previous button using inline CSS.
add_filter('gform_previous_button', 'change_previous_button_style', 10, 2); function change_previous_button_style($previous_button, $form) { return '<button class="button" style="background-color: red; color: white;">Previous</button>'; }