DescriptionUsageParametersExamples1. Change input to button2. Add text after the button3. Remove the button4. Append a JavaScript action to the button5. Append custom CSS classes to the buttonPlacementSource Code
Description
This filter is executed when the form is displayed and can be used to completely change the form button tag (i.e. ).
Usage
The following would apply your function to all forms.
add_filter( 'gform_submit_button', 'your_function_name', 10, 2 );
To target a specific form append the form id to the hook name. (format: gform_submit_button_FORMID)
add_filter( 'gform_submit_button_5', 'your_function_name', 10, 2 );
Parameters
$button_input string
The string containing the tag to be filtered.
$form Form Object
The form currently being processed.
Examples
1. Change input to button
This example changes the default input type to use the button element with an included span, popular for implementing the Sliding Door CSS technique.
add_filter( 'gform_submit_button', 'form_submit_button', 10, 2 );
function form_submit_button( $button, $form ) {
return "";
}
Note: The above is just a quick example showing how to use the filter. Using the above code will prevent the form submitting as the onclick attribute is missing.
Here』s another example which would change all the next, previous, and submit buttons so they use button elements from a single function while maintaining attributes such as onclick from original inputs.
/**
* Filters the next, previous and submit buttons.
* Replaces the forms buttons with
return $dom->saveHtml( $new_button );
}
2. Add text after the button
This example shows how you can add content after the submit button.
add_filter( 'gform_submit_button_36', 'add_paragraph_below_submit', 10, 2 );
function add_paragraph_below_submit( $button, $form ) {
return $button .= "
your text goes here
";
}
3. Remove the button
This example shows how you can remove the submit button for a specific form.
add_filter( 'gform_submit_button_10', '__return_false' );
4. Append a JavaScript action to the button
Adds an onclick action to the submit button.
add_filter( 'gform_submit_button', 'add_onclick', 10, 2 );
function add_onclick( $button, $form ) {
$dom = new DOMDocument();
$dom->loadHTML( '' . $button );
$input = $dom->getElementsByTagName( 'input' )->item(0);
$onclick = $input->getAttribute( 'onclick' );
$onclick .= " addAdditionalAction('Additional Action');"; // Here's the JS function we're calling on click.
$input->setAttribute( 'onclick', $onclick );
return $dom->saveHtml( $input );
}
5. Append custom CSS classes to the button
Adds two custom CSS classes to the submit button.
add_filter( 'gform_submit_button', 'add_custom_css_classes', 10, 2 );
function add_custom_css_classes( $button, $form ) {
$dom = new DOMDocument();
$dom->loadHTML( '' . $button );
$input = $dom->getElementsByTagName( 'input' )->item(0);
$classes = $input->getAttribute( 'class' );
$classes .= " my-custom-class another-one";
$input->setAttribute( 'class', $classes );
return $dom->saveHtml( $input );
}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFFormDisplay::gform_footer() in form_display.php.