Post

gravity forms add css class to submit button

Most of the time you want your contact form buttons to match the buttons on the rest of the site. To do this, you want to add the same css class to your gravity forms.

Add two custom CSS classes to the submit button.

  1. plonk this into functions.php
  2. check the html source of the gravity forms submit buttons on any of your forms
1
2
3
4
5
6
7
8
9
10
add_filter( 'gform_submit_button', 'add_custom_css_classes', 10, 2 );
function add_custom_css_classes( $button, $form ) {
   $dom = new DOMDocument();
   $dom->loadHTML( $button );
   $input = $dom->getElementsByTagName( 'input' )->item(0);
   $classes = $input->getAttribute( 'class' );
   $classes .= " btn btn--primary";
   $input->setAttribute( 'class', $classes );
   return $dom->saveHtml( $input );
}
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.