Support

Account

Home Forums Bug Reports acf_form() id not being set from $args Reply To: acf_form() id not being set from $args

  • Hi John,

    acf_form() code looks like this:

    <?php $options = array(
      'id' => 'data-subsection',
      'post_id' => $submission_post->ID,
      'fields' => array(
        'field_55b1208a40b0e',
        'field_5595c1f4a3e3a',
        'field_5595c20aa3e3b',
        'field_5595c26fa3e3c',
        ),
      'submit_value' => 'Save',
      'updated_message' => '',
      );
      ?>
    <?php acf_form( $options ); ?>

    Form tag always has id=’post’, which is not what docs say, so bug/ or doc issue there. Rendered HTML looks like this:

    <form id="post" class="acf-form" action="" method="post">

    In file api-tmeplate.php starting around line 1277 ( I have been messing w/ this file for testing of ajax submit form, so lines probably don’t exactly match what is in un altered code base) looks like this:

    	// defaults
    	$args = wp_parse_args( $args, array(
    		'id'					=> 'acf-form',
    		'post_id'				=> false,
    		'new_post'				=> false,
    		'field_groups'			=> false,
    		'fields'				=> false,
    		'post_title'			=> false,
    		'post_content'			=> false,
    		'form'					=> true,
    		'form_attributes'		=> array(),
    		'return'				=> add_query_arg( 'updated', 'true', $url ),
    		'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'
    	));
    	
    	$args['form_attributes'] = wp_parse_args( $args['form_attributes'], array(
    		'id'					=> 'post',
    		'class'					=> '',
    		'action'				=> '',
    		'method'				=> 'post',
    	));

    I was able to get my $args id to appear by changing:

    	$args['form_attributes'] = wp_parse_args( $args['form_attributes'], array(
    		'id'					=> 'post',
    		'class'					=> '',
    		'action'				=> '',
    		'method'				=> 'post',
    	));

    to

    	$args['form_attributes'] = wp_parse_args( $args['form_attributes'], array(
    		'id'					=> $args['id'],
    		'class'					=> '',
    		'action'				=> '',
    		'method'				=> 'post',
    	));

    And if no id is supplied in the $args list, then ‘acf-form’ is the form ID, like the docs say it should be.