Home Forums Backend Issues (wp-admin) Problem using acf_form() in backend


Problem using acf_form() in backend

  • Hi everyone, I am currently running into a problem using acf_form() in a custom plugin within the backend.

    I developed a plugin for a client to integrate the library for event management. The purpose of this integration is to be able to manage events (custom post type) from a single calendar view, for that I integrated modal windows that contain forms to add and/or edit events. I have two calls to the acf_form() function inside my code, one outside the loop to create an event (it works fine) and one inside the loop to edit the event (which doesn’t work). The problem is that the form, although it opens and is associated with the post id, I cannot click on the buttons, images cannot be added, etc. It seems to be a js error but in the console it does not show me errors.

    Here is my code, the first custom action is the one I use to add a new post and it works, the second one is the one that doesn’t work.

    If you need more information, I can provide it. From already thank you very much.

    //Acción boton publicar
    function accion_boton_publicar() {
        $publicar_post = [
            'new_post'		=> array(
                'post_type'		=> 'agenda',
                'post_status'	=> 'publish'
            'post_id'         => 'new_post',
            'post_title'      => true,
            'return'          => '', 
            'submit_value'    => 'Publicar',
            'updated_message' => 'El evento fue publicado correctamente'
        acf_form( $publicar_post );
    add_action( 'accion_publicar', 'accion_boton_publicar' );
    //Acción boton editar (test)
    function accion_boton_editar_test($event_number, $event_id) {
        $editar_post_test = [
            'id'                 => 'Formulario-' . $event_number,
            'post_id'            => $event_id,
            'new_post'           => false,
            'post_title'         => true,
            'post_content'       => false,
            'return'             => '',
            'submit_value'       => 'Guardar cambios',
            'updated_message'    => 'El evento se modificó correctamente'
        acf_form( $editar_post_test );
    add_action( 'accion_editar_test', 'accion_boton_editar_test', 10, 2 );
  • The only reason that I can think of is that the ACF scripts are not being loaded, but that should create an error when the button is clicked or it should affect both forms.

    Is this on an admin page where ACF for normally not be included? Have you tried adding a call to acf_form_head()?

  • John, thanks for your help. The problem is something related to what you mention, although the call to acf_form_head() was there since without it it doesn’t even render the form, the problem was that I needed to put this code that apparently calls all the jquery dependencies of the forms rendered with acf_form()

    acf.do_action('append', jQuery('.modal_editar'));

    So I can tell the community if you’re going to use acf_form inside a loop or if you’re going to use it with ajax, make sure you use this code.

    NOTE: Replace .modal_editar with the wrapper of your acf_form()

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

You must be logged in to reply to this topic.