Last active
June 6, 2019 09:10
-
-
Save Bobz-zg/f4aa2dd9c8eeb508f5982803d2735fff to your computer and use it in GitHub Desktop.
Change Gravity Forms submit input to button element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Change submit form <input> element to <button> element for AJAX enabled forms | |
* | |
* @link https://docs.gravityforms.com/gform_submit_button/ | |
*/ | |
add_filter( 'gform_submit_button', function ( $button, $form ) { | |
$dom = new DOMDocument(); | |
$dom->loadHTML( $button ); | |
$input = $dom->getElementsByTagName( 'input' )->item(0); | |
// Skip for all except submit button | |
if ( 'submit' !== $input->getAttribute('type') ) | |
{ | |
return $button; | |
} | |
return sprintf("<button type='%s' onclick='%s' onkeypress='%s' id='%s' class='%s'>%s</button>", | |
$input->getAttribute('type'), | |
$input->getAttribute('onclick'), | |
$input->getAttribute('onkeypress'), | |
$input->getAttribute('id'), | |
$input->getAttribute('class'), | |
$input->getAttribute('value') | |
); | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment