Home › Forums › Front-end Issues › wysiwyg front-end form doesn't work with Ajax call
Hey guys,
So I’ve been trying to make a page that gets certain kinds of forms.
Since it’s not possible to know which form is needed when the page loads I’m trying to load all the forms with ajax.
right now I’ve got the problem that when i load all the forms with ajax, the content is shown like the first attachment.
Somehow it does work when I put a acf_form in the template. Then it is shown as the second attachment.
But only if I have the post_content variable set to true in the options.
My forms are received correctly by ajax and there are no errors anywhere whatsoever.
I think the problem is that the acf_form_head(), which I call at the top of my template, doesn’t load all the content that is needed, when there are no forms on the page when it gets loaded. I’ve also tried to use this function at the ajax call, but this doesn’t work either.
Are there any solutions to this?
Thanks in advance!
Tim
I’ve tried to do some digging around in the code. Without setting up a ajax loading acf form myself I can’t really find a solution.
I believe that inserting a WYSIWYG field causes ACF to enqueue scripts that load into the footer of the page that format the field and since you’re loading the form by ajax these scripts are missing.
Look at the footer script on a page with a form loaded normally and on a page with a form loaded by AJAX and see if there is a difference. If there is then you’ll need to figure out how to load the scripts that are missing.
Not sure if this will help but I found it after writing the above. Have you looked at this http://www.advancedcustomfields.com/resources/acf_form/#AJAX
Hi John,
Thanks for your help so far.
You’re right, it doesn’t load any of the acf files when there isn’t an acf-form at the beginning.
Do you have any idea if there is function which can be called to only load those files?
So what I mean asking is if there is a way to get all the files loaded, even if there isn’t an acf-form.
Thanks a lot!
Tim
To be honest, no. I found this, it was posted a year ago, but there’s nothing specific to wysiwyg editors.
In the file /fields/wysiwyg.php there are two methods in the class get_toolbars
and input_admin_footer_js
that I think are responsible for the code that needed, although I could be wrong. If all else fails you could try to replicate what those function are doing. Don’t know if it will work but it might be worth a try.
You must be logged in to reply to this topic.
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’re hard at work on ACF 6.1, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.