# Use a Real Button for the Gravity Forms Submit

> Replaces the Gravity Forms submit input with a button element that carries your theme's button classes, so it matches the rest of the site and can hold icons.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: gravity-forms, markup, buttons
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gf-button-element/

## Code

```php
$wpide_gf_button_classes = 'wp-element-button';

add_filter( 'gform_submit_button', function ( $button, $form ) use ( $wpide_gf_button_classes ) {
    if ( false === stripos( $button, '<input' ) ) {
        return $button;
    }

    $processor = class_exists( 'WP_HTML_Tag_Processor' ) ? new WP_HTML_Tag_Processor( $button ) : null;
    if ( ! $processor || ! $processor->next_tag( 'input' ) ) {
        return $button;
    }

    $attributes = array();
    foreach ( (array) $processor->get_attribute_names_with_prefix( '' ) as $name ) {
        if ( 'type' === $name || 'value' === $name ) {
            continue;
        }
        $value = $processor->get_attribute( $name );
        $attributes[] = true === $value ? esc_attr( $name ) : sprintf( '%s="%s"', esc_attr( $name ), esc_attr( 'class' === $name ? $value . ' ' . $wpide_gf_button_classes : $value ) );
    }

    $label = (string) $processor->get_attribute( 'value' );

    return sprintf( '<button type="submit" %1$s><span>%2$s</span></button>', implode( ' ', $attributes ), esc_html( $label ) );
}, 10, 2 );
```

## Notes

Set the classes at the top to your theme's button classes, such as wp-element-button or btn btn-primary.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Use a Real Button for the Gravity Forms Submit" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
