Support

Account

Home Forums Front-end Issues Wrap field groups separately for multi-step form

Solving

Wrap field groups separately for multi-step form

  • Hello,
    Ive been able to accomplish what’s suggested here to create a front-end form which creates a post:
    https://support.advancedcustomfields.com/forums/topic/how-to-wrap-field-groups/

    However, I’d like to confirm, should I register two separate forms? Does this cause any unintended issues?

    
    add_action('acf/init', 'test__acf_create_deal');
    function test__acf_create_deal() {
    
        // Check function exists.
        if( function_exists('acf_register_form') ) {
    
            // Register form.
            acf_register_form(array(
                'id'       => 'new-deal-1',
                'post_id'  => 'new_post',
                'field_groups' => array('18'),
                'form' => false,
                'new_post' => array(
                    'post_type'   => 'deal',
                    'post_status' => 'publish'
                ),
                'post_title'  => false,
                'post_content'=> false,
    
            ));
    
            // Register form.
            acf_register_form(array(
                'id'       => 'new-deal-2',
                'post_id'  => 'new_post',
                'field_groups' => array('8'),
                'form' => false,
                'new_post' => array(
                    'post_type'   => 'deal',
                    'post_status' => 'publish'
                ),
                'post_title'  => false,
                'post_content'=> false,
    
            ));
        }
    }

    on the front-end, I have this wrapped in a form:

    	<div id="field-group-1" class="tab">
    	<?php acf_form('new-deal-1');?>
    	</div>
    
    	<div id="field-group-2" class="tab">
    	<?php acf_form('new-deal-2');?>
    	</div>

    Since there’s only one form on the front-end, there should be only one submit however, since there’s two registrations, is this saving twice? is there a better way to achieve this?
    Thanks!

  • Just use one call to acf_form() and include both field groups in the order you want them shown in the “field_groups” setting.

  • Thanks, I did try that originally however, all the fields are displayed without any wrapper. I’d like each field group wrapped in <div id=”field-group-1″ class=”tab”>

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.