will-ashworth
10/27/2016 - 4:08 AM

Filter the submit button in Gravity Forms to change the <input type="submit> element to a <button> element. There's an example in the Gravit

Filter the submit button in Gravity Forms to change the <input type="submit> element to a element. There's an example in the Gravity Forms documentation, but it lacks the proper code to show your custom button text, AND removes important attributes like the onclick that prevents multiple clicks.

<?php

/**
 * Filter the submit button in Gravity Forms to change the <input type="submit> element to a <button> element
 * 
 * @param  string 	$button_input 	Input text source to start from
 * @param  array 	$form         	Form data
 * @return string               	Returns the finished button
 */
function grav_gform_input_to_button( $button_input, $form )
{
    // save attribute string to $button_match[1]
    preg_match('/<input([^\/>]*)(\s\/)*>/', $button_input, $button_match);

    // remove value attribute
    $button_atts = str_replace( 'value=\'' . $form['button']['text'] . '\' ', '', $button_match[1] );

    return '<button ' . $button_atts . '>' . $form['button']['text'] . '<i class="fa fa-refresh"></i></button>';
}
add_filter('gform_submit_button', 'grav_gform_input_to_button', 10, 2);