bookmark_bordergform_submit_button

Description

This filter is executed when the form is displayed and can be used to completely change the form button tag (i.e. <input type=”submit”>).

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 <input> tag to be filtered.

  • $form

    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.

// filter the Gravity Forms button type
add_filter( 'gform_submit_button', 'form_submit_button', 10, 2 );
function form_submit_button( $button, $form ) {
    return "<button class='button' id='gform_submit_button_{$form&#91;'id'&#93;}'><span>Submit</span></button>";
}

Here’s another example which would change all the next, previous, and submit buttons so they use button elements from a single function.

/**
 * Filters the next, previous and submit buttons.
 * Replaces the forms <input> buttons with <button> while maintaining attributes from original <input>.
 *
 * @param string $button Contains the <input> tag to be filtered.
 * @param object $form Contains all the properties of the current form.
 *
 * @return string The filtered button.
 */
add_filter( 'gform_next_button', 'input_to_button', 10, 2 );
add_filter( 'gform_previous_button', 'input_to_button', 10, 2 );
add_filter( 'gform_submit_button', 'input_to_button', 10, 2 );
function input_to_button( $button, $form ) {
    $dom = new DOMDocument();
    $dom->loadHTML( $button );
    $input = $dom->getElementsByTagName( 'input' )->item(0);
    $new_button = $dom->createElement( 'button' );
    $new_button->appendChild( $dom->createTextNode( $input->getAttribute( 'value' ) ) );
    $input->removeAttribute( 'value' );
    foreach( $input->attributes as $attribute ) {
        $new_button->setAttribute( $attribute->name, $attribute->value );
    }
    $input->parentNode->replaceChild( $new_button, $input );

    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 .= "<p>your <a href='http://yourlink.com'>text</a> goes here</p>";
}

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');";
    $input->setAttribute( 'onclick', $onclick );
    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