Home › Forums › Front-end Issues › Editing Form from front end shows blank
Hello,
Im using ACF to create new posts in my custom post type. I also want users to be able to edit posts that they have submitted. Creating new posts works fine and content is passed through successfully. When I attempt to edit a submitted post from the front end, the form shows completely blank, including the post title field. So If I Submit it after editing it creates a new blank post.
I need the form to show the data that was previously entered including the post title, and when I hit submit I need it to update the content.
Right now im including this on both my add-page.php and my edit-page.php
Custom Template:
—
<?php
$new_post= array(
'post_id' => 'firm-profile', // Unique identifier for the form
// PUT IN YOUR OWN FIELD GROUP ID(s)
'field_groups' => array(594), // Create post field group ID(s)
'form' => true,
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => 'Submit Post',
'updated_message' => 'This Post Was Saved, Please Add A New Firm',
'return' => '%post_url%',
);
acf_form( $new_post);
?>
<?php acf_form(); ?>
Functions.php
—
add_filter('acf/pre_save_post', 'save_post_from_frontend');
function save_post_from_frontend( $post_id) {
//Check if user loggin or can publish post
if( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
// check if this is to be a new post
if( $post_id!= 'firm-profile') {
return $post_id;
}
$post= array(
'post_type' => 'providers', // Your post type ( post, page, custom post type )
'post_status' => 'publish', // (publish, draft, private, etc.)
'post_title' => $_POST['acf']['field_5e0b90db10390'],
'return' => '%post_url',
);
// insert the post
$post_id= wp_insert_post( $post);
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
return $post_id;
}
You may want to check that you’ve added acf_form_head(); function to your template file before the get_header(); function.
I don’t know if this makes a difference, but I usually have an array of strings for my field groups:
'field_groups' => array('group_5b97a105e7aa7','group_5b9944bf65405','group_5ba3c0692f67a','group_5b99428f53157','group_5b994530e2cc1');
When editing a post you need to supply the post ID of the post to be edited to acf_form(), otherwise ACF does not know where to get existing data from.
// to edit you need to set this to the post ID to be edited
'post_id' => 'firm-profile', // Unique i
The topic ‘Editing Form from front end shows blank’ is closed to new replies.
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.