Support

Account

Home Forums Front-end Issues Field values not displaying in front-end form

Solving

Field values not displaying in front-end form

  • I’m having trouble getting the any of my fields to display the current values in a front-end form, and I’m not sure where to begin to diagnose the problem.

    All of the field groups show, but the fields do not have the values shown in the back end.

  • Are you using your form within the WordPress Loops? And have you also included acf_form_head()?

    acf_form_head()

  • Yes, I have the acf_form_head() function properly included, and no it’s not in a loop. I got the fields to show up by not using a registered acf form, however, my post object only shows the post selected on the backend and an “allow null” option (“-Select-“). Any thoughts?

  • Are you setting the post_id argument when calling acf_form() https://www.advancedcustomfields.com/resources/acf_form/. If you want to display the fields values for a current post then ACF needs to know what post to use. If you’re not in “The Loop”, as suggested by @pixelbart, then ACF has no way of knowing what post values to display and it is assuming that you’re creating a new post.

  • I see what you are saying, but I thought it defaulted to the current post ID. Anyway, my fields are being populated now, whether I add a varible to the ‘post_ID’ or leave it as ‘false’.
    The only fields that are not functioning properly are two post object fields in a group. I have tested that group on the form, but commented them out for now. They only display the value that has been selected on the backend.

    	$post_ID = get_the_ID();
    
    	$settings = array(
    
    	'id' => 'acf-form',
    	'post_id' => $post_ID,
    	'new_post' => false,
    	'field_groups' => array('group_56f97a1203bfe','group_58b8b6b885fbb'), //'group_57180f67b48be',
    //	'fields' => array(),
    	'post_title' => false,
    	'post_content' => false,
    	'form' => true,
    	/* (array) An array or HTML attributes for the form element */
    //	'form_attributes' => array(),
    	'return' => '',
    	'html_before_fields' => '',
    	'html_after_fields' => '',
    	'submit_value' => __("Update", 'acf'),
    	'updated_message' => __("Post updated", 'acf'),
    	'label_placement' => 'top',
    	'instruction_placement' => 'label',
    	'field_el' => 'div',
    	'uploader' => 'wp',
    	'honeypot' => true,
    	'html_updated_message'	=> '<div id="message" class="updated"><p>%s</p></div>',
    	'html_submit_button'	=> '<input type="submit" class="acf-button button button-primary button-large" value="%s" />',
    	'html_submit_spinner'	=> '<span class="acf-spinner"></span>'
    			
    );
    	
    		acf_form($settings);
  • It should default to the current post ID, if ACF can figure out what the current post ID is.

    First is tries get_the_ID(), then it tries get_queried_object(). It it can’t figure out the post ID then it defaults to “options”

    You can test what ACF is getting by calling the function.

    
    $post_id = acf_get_valid_post_id();
    echo $post_id;
    

    It really depends on where you’re trying to put the form.

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

The topic ‘Field values not displaying in front-end form’ is closed to new replies.