gform_next_button

Description

The “gform_next_button” filter allows the markup for the next button to be changed, giving the user control over how it looks.

Usage

Apply to all forms.

add_filter( 'gform_next_button', 'my_next_button_markup', 10, 2 );

Apply to a specific form.

add_filter( 'gform_next_button_10', 'my_next_button_markup', 10, 2 );

Parameters

  • $next_button string

    The default markup for the next button.

  • $form Form ObjectThe current form.

Examples

Change input to button

See gform_submit_button example 1.

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 ) {
    $fragment = WP_HTML_Processor::create_fragment( $button );
    $fragment->next_token();
    $onclick = trim( (string) $fragment->get_attribute( 'onclick' ) );
    if ( ! empty( $onclick ) && substr( $onclick, -1 ) !== ';' ) {
        $onclick .= ';';
    }
    $onclick .= " addAdditionalAction('Additional Action');";
    $fragment->set_attribute( 'onclick', $onclick );
 
    return $fragment->get_updated_html();
}

Source Code

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

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?