Last active
December 28, 2015 12:36
Allows you to wrap a section of fields on a Gravity Form in a CSS class
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
//* Format specific sections in a Gravity Form - code based on | |
// http://www.jordancrown.com/multi-column-gravity-forms/ and https://sridharkatakam.com/splitting-gravity-forms-fields-into-2-columns/ | |
function gform_format_sections( $content, $field, $value, $lead_id, $form_id ) { | |
if( !IS_ADMIN ) { // only perform on the front end | |
// target section breaks | |
if( $field['type'] == 'section' ) { | |
$form = RGFormsModel::get_form_meta( $form_id, true ); | |
// check for the presence of formatted section class | |
$form_class = explode( ' ', $form['cssClass'] ); | |
$form_class_matches = array_intersect( $form_class, array( 'formatted-sections' ) ); | |
// check for the presence of specific classes in sections | |
$field_class = explode( ' ', $field['cssClass'] ); | |
$field_class_matches = array_intersect( $field_class, array('student-1', 'student-2', 'student-3', 'student-4', 'student-5', 'end-format') ); | |
// if field is a formatted section, perform the list split | |
if( !empty( $form_class_matches ) && !empty( $field_class_matches ) ) { // make sure to target only multi-column forms | |
// retrieve the form's field list classes for consistency | |
$form = RGFormsModel::add_default_properties( $form ); | |
$description_class = rgar( $form, 'descriptionPlacement' ) == 'above' ? 'description_above' : 'description_below'; | |
// close current field's li and ul and begin a new list with the same form field list classes | |
return '</li></ul><ul class="gform_fields '.$form['labelPlacement'].' '.$description_class.' '.$field['cssClass'].'"><li class="gfield gsection empty">'; | |
} | |
} | |
} | |
return $content; | |
} | |
add_filter( 'gform_field_content', 'gform_format_sections', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment