Support

Account

Home Forums Backend Issues (wp-admin) acf_form double posting in wp admin

Solved

acf_form double posting in wp admin

  • Hi!

    I am trying to use acf_form within WordPress Admin. I call a template part via AJAX and replace the HTML inside a metabox. But when I submit / update post for some reason it is triggering acf/pre_submit_form twice so I get 2 identical posts created where as I only need the one.

    I wondered if it was because ‘acf_form_head’ may have already been called – but without my admin_init function nothing posts.

    In my JS I also try to remove the #acf-form-data incase ACF is trying to read these, but still not luck!

    
    function iw_allow_admin_acf_form() {
    	acf_form_head();
    }
    add_action( 'admin_init', 'iw_allow_admin_acf_form' );
    
    
    $.post({
    	url: IWA.ajax_url,
    	data: {
    		action: 'iwa_admin_create_new_lot',
    		post_id: settings.post_id,
    	},
    	beforeSend: function() {
    		t.show_spinner();
    	},
    	complete: function() {
    		t.hide_spinner();
    	},
    	success: function( response ) {
    		if( response.success ) {
    			$('#acf-form-data').remove();
    			$(settings.elements.parent_window).html( response.data.html );
    			acf.do_action( 'append', $( 'form#post' ) );
    		}
    	}
    });
    
    
    function iwa_admin_create_new_lot() {
    
    	if( iwa_check_permissions()	) {
    
    		ob_start();
    
    		get_template_part( 'template-parts/admin/admin-create-lot' );
    
    		$html = ob_get_clean();
    
    		wp_send_json_success( array( 'html' => $html ) );
    
    	}
    
    }
    add_action( 'wp_ajax_iwa_admin_create_new_lot', 'iwa_admin_create_new_lot' );
    

    Hope someone can help.

    Many thanks

  • Resolved – admin_init and AJAX heartbeart was causing the issue

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

You must be logged in to reply to this topic.