Support

Account

Home Forums ACF PRO post_attributes breaking acf_form

Solved

post_attributes breaking acf_form

  • I tried to use the following code to create a new post with acf_form(). The first example is working, and the second is not. Specifically, the second example refreshes the page and then spits all of the ACF postdata into a get variable at the end of the URL, including the nonce. The post is also not successfully created.

    The offending lines of code are the new post_attributes setting in the acf_form() function. I wanted to set a custom class for the form, which is what broke it. Is this a bug or am I using this wrong perhaps?

    Here is an example of the URL I get after submitting the second example: (sorry for the broken-looking code box)

    http://mysiteurl.com/start-campaign/?_acfnonce=d4b66937b0&_acfchanged=1&_acf_form=eyJpZCI6Im5ldy1jYW1wYWlnbi1mb3JtIiwicG9zdF9pZCI6Im5ld19wb3N0IiwibmV3X3Bvc3QiOnsicG9zdF90eXBlIjoiY2FtcGFpZ24iLCJwb3N0X3N0YXR1cyI6InB1Ymxpc2giLCJwb3N0X3RpdGxlIjoidGVtcF90aXRsZSJ9LCJmaWVsZF9ncm91cHMiOlsyN10sImZpZWxkcyI6ZmFsc2UsInBvc3RfdGl0bGUiOnRydWUsInBvc3RfY29udGVudCI6ZmFsc2UsImZvcm0iOnRydWUsImZvcm1fYXR0cmlidXRlcyI6eyJpZCI6Im5ldy1jYW1wYWlnbi1mb3JtIiwiY2xhc3MiOiIgYWNmLWZvcm0gbmV3LWNhbXBhaWduLWZvcm0ifSwicmV0dXJuIjoiXC9zdGFydC1jYW1wYWlnblwvP2ZpbmlzaGVkPXN0ZXAyIiwiaHRtbF9iZWZvcmVfZmllbGRzIjoiIiwiaHRtbF9hZnRlcl9maWVsZHMiOiIiLCJzdWJtaXRfdmFsdWUiOiJDcmVhdGUgQ2FtcGFpZ24iLCJ1cGRhdGVkX21lc3NhZ2UiOiJQb3N0IHVwZGF0ZWQiLCJsYWJlbF9wbGFjZW1lbnQiOiJ0b3AiLCJpbnN0cnVjdGlvbl9wbGFjZW1lbnQiOiJsYWJlbCIsImZpZWxkX2VsIjoiZGl2In0%3D&acf[_post_title]=asdf&acf[field_53bfa58dbb184]=asdf&acf[field_53bfa54bbb181]=20140704&acf[field_53bfa55dbb182]=20140720&acf[field_53bfa574bb183]=3

    Working:(without form_attributes set)

    <?php 
    	$newcampaign = array(
    	'id' => 'new-campaign-form',
    	'post_id' => 'new_post',
    	'new_post' => array(
    		'post_type' => 'campaign',
    		'post_status' => 'publish',
    		'post_title' => 'temp_title',
    		),
    	'post_title' => true,
    	//'form_attributes' => array(
    		//'class' => 'new-campaign-form',
    		//),
    	'field_groups' => array('27'),
    	'submit_value' => 'Create Campaign',
    	'return' => add_query_arg('finished','step2'),
    	);
    	acf_form($newcampaign); ?>

    Not working:

    <?php 
    	$newcampaign = array(
    	'id' => 'new-campaign-form',
    	'post_id' => 'new_post',
    	'new_post' => array(
    		'post_type' => 'campaign',
    		'post_status' => 'publish',
    		'post_title' => 'temp_title',
    		),
    	'post_title' => true,
    	'form_attributes' => array(
    		'class' => 'new-campaign-form',
    		),
    	'field_groups' => array('27'),
    	'submit_value' => 'Create Campaign',
    	'return' => add_query_arg('finished','step2'),
    	);
    	acf_form($newcampaign); ?>
  • Hi @arcanepsyche

    Thanks for the bug report. It seems that by customizing the form_attributes, the very important method="post" is not being added to the form element!

    I’ll do some testing and get this fixed ASAP

  • Hi @arcanepsyche

    Thanks again for the bug report. This has now been fixed and an update will be out soon

  • Re: form_attributes: It would also seem that this also breaks the form validation if you place a custom named ‘id’ in the form_attributes.

  • Re form_attributes: When adding a custom class through this array, the acf code adds it’s own class of “acf-form” to the form class attribute. This causes an output issue within the class attribute as it doesn’t check for the added custom class.

    Expected: <form class=”some_class acf-form” ….

    Actual: <form class=”some_classacf-form” ….

  • Hi @ballyhoos

    Thanks for the feebback. Looking at the code (api-template.php:1226) the ‘acf-form’ looks to be appended with a space:

    $args['form_attributes']['class'] .= ' acf-form';

    Is this the code you have in your version?

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

The topic ‘post_attributes breaking acf_form’ is closed to new replies.