Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save markusvonplunkett/600f3519c142ff5271885135c554a1f2 to your computer and use it in GitHub Desktop.
Save markusvonplunkett/600f3519c142ff5271885135c554a1f2 to your computer and use it in GitHub Desktop.
Gravity Form Button Customisation
// 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