Support

Account

Home Forums Front-end Issues acf_form() and single page app Reply To: acf_form() and single page app

  • ***
    THIS IS NOT THE SOLUTION, BUT I CAN’T CHANGE THIS SETTING ANYMORE. PLEASE SCROLL DOWN TO MY LAST COMMENT TO SEE THE REAL SOLUTION.
    ***

    I think I got it: instead of the function acf_form_head(), I placed this code on every template’s beginning:

    
    // prevents the default ACF styles and scripts from being enqueued
    acf()->input->enqueued = true;
    // checks for a form submit
    acf()->form_front->check_submit_form(); 
    

    Then I used jQuery to do the form submit myself (warning, using ES2015):

    
    $('form').each((i, el) => {
      let $form = $(el);
      let action = $form.attr('action');
      let method = $form.attr('method');
      if( !action || typeof action === 'undefined' ) {
        action = window.location.href;
      }
      if( !method || typeof method === 'undefined' ) {
        method = 'get';
      }
      $form.submit((e) => {
        e.preventDefault();
        $('html').addClass('is-loading');
        $.ajax({
          url: action,
          method: method,
          data: $form.serialize()
        }).then((response) => {
          $('html').removeClass('is-loading');
          console.log( 'message sent!' );
        });
      });
    });