Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KyleIrving/2cfc9cbbac04a366dded to your computer and use it in GitHub Desktop.
Save KyleIrving/2cfc9cbbac04a366dded to your computer and use it in GitHub Desktop.
<?php
// filter the Gravity Forms button type
add_filter("gform_submit_button_1", "form_submit_button", 10, 2);
function form_submit_button($button, $form){
return "<button class='button' id='gform_submit_button_{$form["id"]}'><span><i class='fa fa-share fa-2x'></i> Send </span></button>";
}
//Change hook of gform_submit_button_X to the form that you are using
//Change <span><i class='fa fa-share fa-2x'></i> Send </span> to Font awesome and text of your choice
@ninjaval
Copy link

ninjaval commented Feb 8, 2017

Is there a way we can specify a certain icon for each form? For example, I have one form that needs a paper plane, and another one needs a download icon for the submit button. When I try adding the same code, but change the form id # I get an error saying I can't use the "form_submit_button" twice. Any advice appreciated!

@schalkjoubert
Copy link

@ninjaval Simply copy the whole filter and function, and add the relevant form number.

Gravity Form ID 2:
add_filter("gform_submit_button_2", "form_submit_button_2", 10, 2); function form_submit_button_2($button, $form){ return "<button class='button' id='gform_submit_button_{$form["id"]}'><span><i class='fa fa-newspaper-o'></i> SUBSCRIBE</span></button>"; }

Gravity Form ID 8:
add_filter("gform_submit_button_8", "form_submit_button_8", 10, 2); function form_submit_button_8($button, $form){ return "<button class='button' id='gform_submit_button_{$form["id"]}'><span><i class='fa fa-download'></i> DOWNLOAD</span></button>"; }

@temsool
Copy link

temsool commented Sep 27, 2018

thanks

@nacm
Copy link

nacm commented Sep 29, 2018

If you are using this method and with update to Gravity Forms v2.3.4 the submit button does not work.

@scottkoons
Copy link

This is an awesome, straightforward example and worked perfectly! Thanks for sharing!!

@barking-horse
Copy link

To use the button backend text, you should do something like that :

add_filter( 'gform_submit_button', 'form_submit_button', 10, 2 ); function form_submit_button( $button, $form ) { return "<button class='button gform_button' id='gform_submit_button_{$form['id']}'><span class="icon icon-arrow" aria-hidden="true"></span>{$form['button']['text']}</button>"; }
And of course aria-hidden="true" for a right accessibility as you put an icon in your button.

The important for the text is {$form['button']['text']}

@Klemart3D
Copy link

{$form['button']['text']} not works for me, I have to use {$form['buttonText']} instead. (GF v2.6.3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment