Using Gravity Forms ‘gform_next_button’ PHP action

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

Usage

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

Parameters

  • $next_button (string): The default markup for the next button.
  • $form (Form Object): The current form.

More information

See Gravity Forms Docs: gform_next_button

Examples

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_next_button', 'form_next_button', 10, 2 );
function form_next_button( $button, $form ) {
    return "<button class='button gform_next_button' id='gform_next_button_{$form['id']}'><span>Next</span></button>";
}

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.

Append a JavaScript action to the button

Adds an onclick action to the submit button.

add_filter( 'gform_next_button', 'add_onclick_to_next_button', 10, 2 );
function add_onclick_to_next_button( $button, $form ) {
    $dom = new DOMDocument();
    $dom->loadHTML( $button );
    $input = $dom->getElementsByTagName( 'input' )->item(0);
    $input->setAttribute( 'onclick', 'myCustomFunction()' );
    return $dom->saveHTML( $input );
}