Last active
March 8, 2018 15:01
-
-
Save sewmyheadon/1496db0a0bea4e5e3eba to your computer and use it in GitHub Desktop.
Add Bootstrap styles to Gravity Forms fields
This file contains hidden or 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
/** | |
* Adding Bootstrap Styles to Gravity Forms | |
*/ | |
add_filter("gform_field_content", "bootstrap_styles_for_gravityforms_fields", 10, 5); | |
function bootstrap_styles_for_gravityforms_fields($content, $field, $value, $lead_id, $form_id){ | |
// Currently only applies to most common field types, but can be expanded. | |
if($field["type"] != 'hidden' && $field["type"] != 'list' && $field["type"] != 'multiselect' && $field["type"] != 'checkbox' && $field["type"] != 'fileupload' && $field["type"] != 'date' && $field["type"] != 'html' && $field["type"] != 'address') { | |
$content = str_replace('class=\'medium', 'class=\'form-control medium', $content); | |
} | |
if($field["type"] == 'name' || $field["type"] == 'address') { | |
$content = str_replace('<input ', '<input class=\'form-control\' ', $content); | |
} | |
if($field["type"] == 'textarea') { | |
$content = str_replace('class=\'textarea', 'class=\'form-control textarea', $content); | |
} | |
if($field["type"] == 'checkbox') { | |
$content = str_replace('li class=\'', 'li class=\'checkbox ', $content); | |
$content = str_replace('<input ', '<input style=\'margin-left:1px;\' ', $content); | |
} | |
if($field["type"] == 'radio') { | |
$content = str_replace('li class=\'', 'li class=\'radio ', $content); | |
$content = str_replace('<input ', '<input style=\'margin-left:1px;\' ', $content); | |
} | |
return $content; | |
} // End bootstrap_styles_for_gravityforms_fields() | |
add_filter("gform_submit_button", "bootstrap_styles_for_gravityforms_buttons", 10, 5); | |
function bootstrap_styles_for_gravityforms_buttons($button, $form){ | |
$button = str_replace('class=\'gform_button', 'class=\'gform_button btn btn-primary', $button); | |
return $button; | |
} // End bootstrap_styles_for_gravityforms_buttons() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment