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!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.