I’m working on a project where a custom post type is editable on the frontend via ACF fields without any user login required. You only need the URL for the edit profile with the access key. The issue I’m facing is when I open the link in private or for the first time in a new browser and submit the form after changes it does not save anything and does not return to the given return URL. However on updating second time it works fine.
Using acf_form_head() at the top of the template and using form tag to wrap the fields.
$query_args = array( 'access-key' => $_GET['access-key'], 'post-id' => $_GET['post-id'], 'field_group_id' => $next_field_group_id ); $return_url = add_query_arg( $query_args, get_permalink( 6232 ) ); ob_start(); echo '<div class="acf-form" id="acf-form-left">'; $acf_args12 = array( 'id' => 'acf-form-one', 'post_id' => $post_id, 'fields' => $keyvalleft, 'uploader' => 'basic', 'form' => false, 'html_before_fields' =>'<div class="container"><div class="left">', 'html_after_fields' => '</div></div>', ); acf_form( $acf_args12 ); echo '</div>'; echo '<div class="acf-form" id="acf-form-third">'; $imageGallery = array( 'field_5a3d86641e590', 'field_5a3d86901e591', 'field_5a3d86961e592', 'field_5a3d869f149a2', ); $acf_args = array( 'id' => 'acf-form-two', 'post_id' => $post_id, 'fields' => $imageGallery, 'class' => 'new-campaign-form', 'uploader' => 'basic', // 'return' => $return_url, 'form' => false, 'submit_value' => __("Save and Continue", 'acf'), ); acf_form( $acf_args ); echo '</div>'; echo '<div class="acf-form" id="acf-form-right">'; $acf_argsright = array( 'id' => 'acf-form-three', 'post_id' => $post_id, 'fields' => $keyvalright, 'return' => $return_url, 'uploader' => 'basic', 'form' => false, 'html_before_fields' =>'<div class="container"><div class="right">', 'html_after_fields' => '</div></div>', 'submit_value' => __("SAVE DRAFT", 'acf'), ); acf_form( $acf_argsright ); echo '<div class="acf-form-submit"> <input type="submit" class="acf-button button button-primary button-large" value="Save Draft"><span class="acf-spinner"></span></div>'; echo '</div>'; //acf_form( $acf_args12 ); $return .= ob_get_clean(); return $return;
I don’t see any form tags, I’m assuming they were omitted when you copied code. If the form tags are there and acf_form_head() is called before any page output then I don’t see anything that should really prevent it from working.
Have you tried testing with just one acf_form() call at a time to see if they work independently?
I have mentioned that I am using acf_form_head() and form tags to wrap the code.
acf_form_head(); get_header(); ?> <div class="sectiontlp" style="display:none;"> </div> <div id="main" class="page editlistingtemplate"> <form action="" class="acf-form" method="post"> <div id="content"> <?php print_r($_POST); $builder = new BGC_Content_Builder(); echo $builder->content; ?> </div> </form> </div>
Its working fine on my local machine somehow. Not sure what the issue is. I have followed the instructions for acf_form clearly as mentioned. I can see the data is fine in the $_POST variable its just not saving.
Somehow its happening due to a Cache setting on the hosting platform. Whenever I disable Varnish(Caching option) on Cloudways platform it saves on the first go.
Otherwise if the caching is on it doesn’t save on the first submit just refreshes and then I have to make the changes again and submit then it works.
Any advice regarding this?
You must be logged in to reply to this topic.
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!