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.
Opens WPIDE on
Code
$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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.