Created
October 16, 2018 15:57
-
-
Save markusvonplunkett/600f3519c142ff5271885135c554a1f2 to your computer and use it in GitHub Desktop.
Gravity Form Button Customisation
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
// filter the Gravity Forms button type | |
add_filter('gform_submit_button', __NAMESPACE__ . '\\form_submit_button', 10, 2); | |
function form_submit_button($button, $form) | |
{ | |
// Add custom classes to your button | |
$classes = 'btn1 form-submit-btn'; | |
// Replace default input tag with button opening tag | |
$button = str_replace('<input', '<button', $button); | |
// Replace default closing input tag with button closing tag | |
$button = str_replace('/>', '></button>', $button); | |
// Outputs clasess on button tag | |
$button = str_replace("class='", "class='" . $classes . " ", $button); | |
// Preg_match gets an array of regex matches to the 3rd param | |
preg_match("/value='([^\']*)'/", $button, $value); | |
// Adds span tags to all buttons by default and outputs value set via admin form control | |
$button = str_replace('></', '><span>' . $value[1] . '</span></', $button); | |
return $button; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment