amp-form?
-
I’ve tried adding an AMP example form (from https://ampbyexample.com/components/amp-form/) to a page. I have amp-forms loaded but the form is not displayed. Do you have any ideas why this happens?
-
Hey @alanp57
Thank you so much for using our plugin.
Did you add the script?
To display AMP-form, you have to put a script in the header of AMP version of your website.
`<script async custom-element=”amp-form” src=”https://cdn.ampproject.org/v0/amp-form-0.1.js”></script>
Add this script in AMP Settings > Advanced Settings > Paste the script in Enter HTML in Header
Hope it helps.
Thanks for replying.
I did says, “I have amp-forms loaded.” That means that<script async custom-element=”amp-form” src=”https://cdn.ampproject.org/v0/amp-form-0.1.js”></script>is on the page. Yet the form HTML is not displayed.
-
This reply was modified 9 years, 2 months ago by
AlanP57.
Hey @alanp57
That’s really strange. It must work. Implementing Forms in AMP are quite complex.
I recommend you to refer AMP documentation thoroughly > https://ampbyexample.com/components/amp-form/ it works out of the box. However, it’s bit complex.
I have this same problem.
I have the code for amp-forms and amp-iframe in head.
I can see the includes in page source.Loading iframes works.
The form, however, is stripped entirely.I added the script to the head as well but it seems that AMP strips out the form tags before that script even has a chance to validate them.
This is an example url that is currently live.
https://www.verbouwkosten.com/kunststof-kozijnen/vergelijk-nl/And this is the AMP version:
https://www.verbouwkosten.com/kunststof-kozijnen/vergelijk-nl/amp/As you might be able to tell, the form that appears on the regular page is missing on the AMP. And the AMP also has links to related pages that the regular page does not have.
The first form is generated by a custom built plug-in. When that is filled out, a second form built with Gravity forms is displayed.
I also created a test page here:
https://www.verbouwkosten.com/test20170718/amp/This includes the form code copied directly from ampbyexample.com.
Hi @tharkon,
All form elements are getting stripped by default to validate the page. so if we need any forms to work with in the content then we must need to make sure amp-blacklist sanitizer must be stopped on that page, you need to modify the blacklist sanitizer and unset it from the content sanitizer, so it will not strip the form content and then add the validated form elements and it should work.
Hope it helps
Marqas
Hi @ampforwp,
We are having the same issue that Tharkon reported. I removed ‘input’, ‘select’ ,
‘option’, ‘form’ from the amp-blacklist sanitizer and now our form-element (=calculator) is working properly and the page is still AMP valid.
We are a bit concerned though what happens if the plugin is updated. I guess the removed elements will be added again to the sanitizer file. Correct?
As <form> has been supported by AMP for a while by now I would like to know why you don’t remove it from your plugin’s blacklist.Thanks a lot for your support.
What I did, which remains after an update, was add the following to functions.php.
add_filter( 'amp_content_sanitizers', 'remove_AMP_Blacklist_Sanitizer', 10, 2 ); function remove_AMP_Blacklist_Sanitizer( $sanitizer_classes, $post ) { unset($sanitizer_classes[ 'AMP_Blacklist_Sanitizer' ]); return $sanitizer_classes; }But that might be a bit overkill, since it doesn’t just allow forms, it allows everything. I hadn’t noticed the list you mentioned, I might have to play around with that, but there might not be a hook that deep into the class.
-
This reply was modified 8 years, 9 months ago by
Tharkon.
-
This reply was modified 9 years, 2 months ago by
The topic ‘amp-form?’ is closed to new replies.