Support

Account

Home Forums Feature Requests Wrap field groups in unique divs with acf_form() (working feature code included) Reply To: Wrap field groups in unique divs with acf_form() (working feature code included)

  • ok here are my core hack updates to allow for wrapping of field groups and optional display of field group titles in front end forms

    usage:

    $args = array(
        wrap_field_groups' => false // don't wrap [default]
        wrap_field_groups' => true // wrap without title
        wrap_field_groups' => 'show_title' // wrap with title
    );
    acf_form($args);

    api-field.php
    line 474 – 480

    // ACF5 core hack BEGIN
    // are we opening or closing a field group?
    if( $field['field_group_wrap'] === true ) {
    	echo $field['value'];
    	return;
    }
    // ACF5 core hack END

    api-template.php
    line 1273 – 1275

    // ACF5 core hack BEGIN		
    'wrap_field_groups'		=> false,
    // ACF5 core hack END

    line 1386 – 1401

    // ACF5 core hack BEGIN
    // check for field group wrap
    if( !empty( $args['wrap_field_groups'] ) ){
    	$wrapper = array(
    			'field_group_wrap' => true,
    			'value' => '<div id="'.$field_group['key'].'" class="acf_form_field_group_wrap">'
    	);
    
    	if ( 'show_title' === $args['wrap_field_groups']) {
    		$wrapper['value'] = '<div id="'.$field_group['key'].'" class="acf_postbox acf_form_field_group_wrap">
    									<h3 class="acf_form_field_group_title">'.$field_group['title'].'</h3>';
    	}
    
    	$fields[] = $wrapper;
    }				
    // ACF5 core hack END

    line 1408 – 1416

    // ACF5 core hack BEGIN
    // check for field group wrap
    if( !empty( $args['wrap_field_groups'] ) ){
    	$fields[] = array(
    		'field_group_wrap' => true,
    		'value' => '</div><!-- end field group -->'
    	);
    }				
    // ACF5 core hack END