I have this simple form in my front end and a custom post type in backend.
I just want the form to post as a draft in backend with title + custom field “message” with the key “field_5e3a9e24168df”
<?php
defined('ABSPATH') || exit;
acf_form_head();
$fields = array(
'field_5e3a9e24168df', // message
);
acf_register_form(array(
'id' => 'new-message',
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'bible_dor',
'post_status' => 'draft',
'post_title' => $_POST['acf']['_post_title'],
'field_5e3a9e24168df' => $_POST['acf']['field_5e3a9e24168df']
),
'post_title' => true,
'fields' => $fields,
'post_content' => false,
'return' => home_url('bibliographie'),
'submit_value' => __("Laisser un message", 'jcd'),
'updated_message' => __("Message enregistré", 'jcd'),
));
// Load the form
acf_form('new-message');
?>
My form is showing, with correct fields etc but when i save, nothing is saved in backend, any idea?
Hi, is the acf_form_head() function called before any HTML output? As explained in the docs, the acf_form_head() function is used to process, validate and save the submitted form data created by the acf_form() function. It will also enqueue all ACF related scripts and styles for the form to display correctly.
This function must be placed before any HTML has been output, preferably above the get_header() function of your theme file.
M
Yes it was there, finally decided to do it differently having only <?php acf_form(‘new-message’); ?> in my template and the acf_register_form() in functions.php using hook add_action(‘acf/init’, ‘my_acf_init’);
Seem that having the acf_register_form() directly in the template doesn’t work anymore in last acf version.