Home Forums ACF PRO acf_form hidden field Reply To: acf_form hidden field

  • Got this working. For the hidden field issue, we used a field from a different field group (that isn’t part of the frontend form) and used the html_after_fields function:

    <?php acf_form(array(
    	'post_id'		=> 'new_post',
    	'field_groups' => array( GROUP-ID ),
    	'new_post'		=> array(
    		'post_type'		=> 'reviews',
    		'post_status'		=> 'draft',
    	'submit_value'		=> 'Create a new review',
    	'updated_message'   => 'Thank you for the review!',
    	'html_after_fields' => '<input type="hidden" name="acf[field_KEY-FROM-ADMIN]" value="OUR-POST-VALUE"/>',
    )); ?>

    For the other issue with post_title, it seems to have been an issue with this form value (text field) not being available when the form saved the new post the standard way. So in functions.php, we have this:

    function acf_review_before_save_post($post_id) {
    	if (empty($_POST['acf']))
    	$_POST['acf']['_post_title'] = $_POST['acf']['field_KEY-FROM-ADMIN'];
    	return $post_id;
    add_action('acf/pre_save_post', 'acf_review_before_save_post', -1); ?>