Support

Account

Home Forums Front-end Issues Load acf_form() on click with ajax (almost working)

Helping

Load acf_form() on click with ajax (almost working)

  • Hi,

    I’m using acf_form() for displaying my options page on the frontend.I do this with ajax. Everything works except that the tabs and color pickers are not loaded. The select fields and repeaters work.

    The code below is not on click but it executes on the Div with #test as ID. I can make it on click later…

    If I don’t load acf_form() with ajax at the same position in the php file, it works.
    What am I missing?

    <script>
        jQuery(document).ready(function($) {
       
        $.ajax({
            url: ajaxurl,
            data: {
                'action':'example_ajax_request',
            },
            success:function(data) {
                // This outputs the result of the ajax request
                $('#test').html(data);
            },
            error: function(errorThrown){
                console.log(errorThrown);
            }
        });  
                  
    });
     
    </script>

    And inside functions.php

    
    <?php
    function example_ajax_request() {
     
    if ( isset($_REQUEST) ) {
                 
    acf_enqueue_uploader();
    
    $args = array(
    'post_id' => 'options',
    'form_attributes' => array(
    'class' => 'new-campaign-form',
    'id'=>'modalAjaxTrying'
    ),
    'field_groups' => array(16), //field group id
    'submit_value' => __("Save and Continue", 'acf'),
    );
    
    acf_form( $args ); 
             
         
        }
        
       die();
    }
     
    add_action( 'wp_ajax_example_ajax_request', 'example_ajax_request' );
    ?>

    How can I fix this? Ideas are welcome :), TY

  • On this page, almost at the end, see the section titled JavaScript

    you need to call acf.do_action('append', $('#popup-id'));

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

The topic ‘Load acf_form() on click with ajax (almost working)’ is closed to new replies.