Home › Forums › Pre-purchase Questions › acf_form and AMP
I just stumbled upon Advanced Custom Fields and I am in love with all of the advanced features this plugin has. I will definitely be getting the pro lifetime license.
My question has to do with acf_form and the official AMP plugin. Does the front-end forms this feature create load js files on the pages they are embedded on? Also, do the forms contain the action-xhr attribute when the form method is post as per the AMP guidelines? if not, is this something I could easily add?
1) Yes, it loads JS, all of the code required to make the fields work is loaded.
2) No it does not and does not and ACF does not support natively submitting forms using AJAX
In order to do this you would need to build your own form and your own form processor that can be called using ajax in WP that would properly save all the submitted values and not use acf_form() at all.
Thanks, @hube2,
in regards to your answer to #1, does it load the JS site-wide (aka on every page) or on just the page where the acf_form() is added?
I have looked into other form software and some like Toolset Forms loads JS across the whole site, while others like Gravity Forms only loads the JS on the pages where a form is added.
If its like Gravity Forms, I can still use acf_form() and just set those specific pages to not use AMP. If it loads site-wide, however, I can’t use it as I want the majority of the website to validate as AMP.
This depends on how you implement it. The function acf_form_head()
call that is required needs to be before any html is output. Calling this function is what causes all of the JS to be loaded and what causes the form to be processed when submitted.
If you put this in your header.php file then it will be loaded site wide.
If this is put in the template file for the page just before get_header()
then it will be loaded on any page using that template.
You can have it loaded on just pages that have use acf_form()
by creating a page template that will only be used for these pages.
There are potentially other ways that this can be done as well but each gets a little more complicated.
For example, you could have an init action
add_action('init', 'some_function_name_here');
some_function_name_here() {
if (/*some condition*/) {
acf_form_head();
}
}
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 2023
© 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.