Support

Account

Home Forums Front-end Issues Front End Form and register_field_group not working together

Solved

Front End Form and register_field_group not working together

  • I am creating my field groups locally via the backend GUI and when I deploy the site I export the fields to my functions.php

    This is code from the front end form tutorial:`$options = array(
    'post_id' => $post->ID, // post id to get field groups from and save data to
    'field_groups' => array(), // this will find the field groups for this post (post ID's of the acf post objects)

    …`

    Since on my production server the field groups are registered via PHP there is no acf post object ID I could pass in. Omitting the argument will render all field groups which is not what I want.

    Any hints how to select field groups for the front end form that are registered via PHP?

  • Hi @JanBeck

    I’m missing quite a bit of information to tell you exactly why this isn’t working.

    Are you correctly using location rules for your field group?
    If so, all you need to do is not pass through any ‘field_groups’ in the args and allow ACF to find the correct field groups based on the $post that you are trying to edit.

  • You are right @elliot, I left out some bits of information.

    I am using the form on the Buddypress user profile page so users can add more info about themselves. I have two calls of register_field_group() in my functions.php – one for the edit view of the user profile and one for the public view of the profile. Basically a user edits the profile, previews it and can hit a little checkbox below to “publish the profile” which internally restricts the user from changing the profile again (client wants to review user profiles so this is necessary).

    So I have these two field_groups that I would like to display in two different locations of the user profile in the theme. Omitting ‘field_groups’ will render both field groups at both locations of the form as I have these location rules in my registration calls:

    ...
    'location' => array (
    	array (
    		array (
    			'param' => 'ef_user',
    			'operator' => '==',
    			'value' => 'all',
    			'order_no' => 0,
    			'group_no' => 0,
    		),
    	),
    ),
    ...
  • Hi @JanBeck

    Sounds like all you need to do is speficy the correct field group.

    Each field group (even if it is registered via PHP) contains a unique ID.

    Use this id int eh field_group args like so:

    
    $options = array(
    'post_id' => $post->ID, 
    'field_groups' => array( 'acf-user' )
    ...
    
  • thanks @elliot,

    I didn’t specify the field_groups as an array. That’s what caused the error. D’oh.

  • Thanks, I was having the same issue and this also sorted it for me.

    EDIT: I had asked a question but it happens it was a problem with the live wp installation and not the plugin, thanks!

  • Somehow the array for the field_groups doesn’t work with the keys of the field for me.
    I’m using it as followed:

    
    'field_groups' => array('field_5630c8fa19205', 'field_564332d068410')
    

    Am I doing this the right way or should it be done different?
    I know it’s possible to use the post ID as well, but I need to use the keys for this one.

    Thanks in advance!

    Tim

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

The topic ‘Front End Form and register_field_group not working together’ is closed to new replies.