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;
});
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.