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:
<?php
function acf_review_before_save_post($post_id) {
if (empty($_POST['acf']))
return;
$_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); ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.