Support

Account

Home Forums General Issues Frontend form – post via ajax? Reply To: Frontend form – post via ajax?

  • Hi @hwk , I testet your code and it works great! The only thing now still missing is a way to hook into the validation ajax request, so that I could include image upload capabilities, as described by @valpe . Do you know how to do that? You seem like a pro 😉

    …in the meantime, I used this code (still two ajax requests, but much cleaner than my original solution):

    
    acf.add_filter('validation_complete', ( json, $form ) => {
      // if errors?
      if( json.errors ) {
        return json;
      }
    
      var formdata = new FormData($form[0]);
    
      $.ajax({
        url: window.location.href,
        method: 'post',
        data: formdata,
        cache: false,
        processData: false,
        contentType: false,
        success: (data) => {
          acf.validation.toggle($form, 'unlock');
          //... show success message ...
        }
      });
    
      return json;
          
    });