Home › Forums › Front-end Issues › generating acf form with ajax › Reply To: generating acf form with ajax
I’m also struggling to get a working ACF form created by ajax. I’ve tried a couple of the acf.do_action methods that I found but none fully solved the issues. I will say my form has working js validation, and a working select list filter… so it mainly working, and maybe this sample code will help somebody with the issues they are finding. What I can’t get around, is that when I submit the form I land on /wp-admin/admin-ajax.php?updated=true because the ajax doesn’t seem to apply preventDefault() and it acts like a non-ajax form submission.I tried adding my own .submit and using preventDefault but then the form never submits and I see the ajax circle loading endlessly and no data is saved. So using your own preventDefault in a submit handler seems to break the form processing by ACF.
$.post( devcoreAjax.url, data, function( response ) {
$('#add-record .modal-body').html( response );
acf.do_action('append', $('#add-record .modal-body form') );
acf.do_action('ready', $('#add-record .modal-body form') );
$('#add-record .modal-body form').submit( function(e) {
e.preventDefault();
});
$('#add-record').modal('show');
});
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.