Support

Account

Home Forums ACF PRO ACF Form does not save on initial submit.

Solving

ACF Form does not save on initial submit.

  • 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;
  • Does $post_id already exist? Or are you attempting to create a new post?

  • Editing an existing post.

  • 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.

  • As I said, given the information I have I don’t see anything that should cause the issue that you’re seeing.

  • 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?

  • I’ve done some looking and I can’t find any information on why this would happen. Maybe talk to your hosting provider and see if they can help you. Maybe there is a way to disable the cache when a form is submitted.

  • Thanks its an unusual issue, I was lucky to catch it in the first place. I have fixed the issue by just disabling the service for the particular application. Thanks for the support.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.