Skip to content

Instantly share code, notes, and snippets.

@jameslaws
Created December 11, 2013 15:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameslaws/7911909 to your computer and use it in GitHub Desktop.
Save jameslaws/7911909 to your computer and use it in GitHub Desktop.
Group Fields in Ninja Forms This code allows you to group fields by adding the nf-open-field-group to the first field in a group and nf-close-field-group to the last field in a group. Fields must already be in proper order.
<?php
function nfjal_open_field_group( $field_id, $data ) {
if ( !$class = $data['class'] ) {
$class = '';
}
if ( strstr( $class, 'nf-open-field-group' ) ) {
$class = nfjal_get_group_wrap_class( $class );
echo '<div class="' . $class . '">';
}
}
add_action( 'ninja_forms_display_before_opening_field_wrap', 'nfjal_open_field_group', 10, 2 );
function nfjal_close_field_group( $field_id, $data ) {
if ( !$class = $data['class'] ) {
$class = '';
}
if ( strstr( $class, 'nf-close-field-group' ) ) {
echo '</div>';
}
}
add_action( 'ninja_forms_display_after_closing_field_wrap', 'nfjal_close_field_group', 10, 2 );
function nfjal_get_group_wrap_class( $class ) {
$class = str_replace( '-group', '', $class );
$class = str_replace( '-open', '', $class );
$x = 0;
$custom_class = '';
if ( isset( $class ) AND !empty( $class ) ) {
$class_array = explode(" ", $class );
foreach($class_array as $class){
$custom_class .= $class;
if($x != (count($class_array) - 1)){
$custom_class .= " ";
}
$x++;
}
}
if($custom_class != ''){
$custom_class = str_replace( ' ', '-group ', $custom_class );
$field_wrap_class .= ' ' . $custom_class . '-group';
}
return $field_wrap_class;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment