Support

Account

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

  • Hi @pooledge,
    I have find a solution for you. The problem is the serialization of the file. If you want to bypass this you have to use ‘FormData’. This code works for me with the basic uploader :

    acf.add_action('submit', function($form){
    
                var formdata = new FormData($form[0]);
    
                $.ajax({
                    url: window.location.href,
                    method: 'post',
                    data: formdata,
                    cache: false,
                    processData: false,
                    contentType: false,
                    success: function(data) {
                        acf.validation.toggle($form, 'unlock');
                        $form.prepend('<div class="acf-error-message -success">' + data + '</div>');
                        $('html,body').animate({
                            scrollTop: $form.offset().top - 150
                        }, 500);
                        $('.acf-form button[type="submit"]').prop('disabled', false);
    
                    }
                });
            });

    I hope this code will help you! 😉 Thanks!