Home › Forums › General Issues › Frontend form – post via ajax? › Reply To: Frontend form – post via ajax?
@ibes Actually, yes! There is a submit
action now. Very handy. Also, I included a fix for empty file inputs breaking Safari, the new IE… ;(
acf.addAction('submit', ( $form ) => {
// Fix for Safari Webkit – empty file inputs kill the browser
// https://stackoverflow.com/a/49827426/586823
let $fileInputs = $('input[type="file"]:not([disabled])', $form)
$fileInputs.each(function(i, input) {
if( input.files.length > 0 ) {
return;
}
$(input).prop('disabled', true);
})
var formData = new FormData( $form[0] );
// Re-enable empty file $fileInputs
$fileInputs.prop('disabled', false);
acf.lockForm( $form );
$.ajax({
url: window.location.href,
method: 'post',
data: formData,
cache: false,
processData: false,
contentType: false
}).done(response => {
console.log(response);
acf.unlockForm( $form );
});
});
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.