Hi there!
I'm using the Genesis eNews Extended plugin to create a form and have my website visitors subscribe to my newsletter. I recently noticed that when I use AMP, the form does not work at all. I get an error message that says: "Your submission failed. The server responded with (code ). Please contact the developer of this form processor to improve this message. Learn More"
Do I need to add some headers or something to a filter in functions.php? Or is this a server issue?
Thanks!
Please share the URL for the AMP page that has the form on it.
Sure! Sorry about that!
Also, the console error is:
Access to fetch at 'https://thepostmansknock.boldermail.com/subscribe?_wp_amp_action_xhr_converted=1&__amp_source_origin=http%3A%2F%2Fthepostmanskck.staging.wpengine.com' from origin 'http://thepostmanskck.staging.wpengine.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
log.js:252 [amp-form] Form submission failed: Error: XHR Failed fetching (https://thepostmansknock.boldermail.com/...): Failed to fetch​​​
at ab (https://cdn.ampproject.org/v0.js:28:169)
at Xa.f.createExpectedError (https://cdn.ampproject.org/v0.js:23:343)
at https://cdn.ampproject.org/v0.js:142:154
Thanks. I'm also seeing this:

I can see that the HTTP response headers for a request are:
HTTP/1.1 302 Found
Date: Thu, 30 Jan 2020 06:46:30 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
X-Powered-By: PHP/7.1.28
Location: https://thepostmansknock.com/welcome-to-the-blog-list/
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
This is not expected. I expected instead of a Location header to see an AMP-Redirect-To header. I believe this is an issue with the Genesis eNews Extended plugin. Is that the one you are using?
Yes. That's the plugin I'm using. Once the form is submitted with the plugin and the user is subscribed, my mailing system redirects the user to https://thepostmansknock.com/welcome-to-the-blog-list/.
Is that redirection not compatible with AMP?
Oh, also I'm seeing the form having this action URL:
https://thepostmansknock.boldermail.com/subscribe?_wp_amp_action_xhr_converted=1
That's not expected. Should it not rather be:
https://thepostmanskck.staging.wpengine.com/subscribe?_wp_amp_action_xhr_converted=1
Have the URLs perhaps not been replaced properly on your staging site?
The redirection should be compatible with AMP. In particular if the redirection is being done via wp_redirect() (as it should).
You can see that the plugin intercepts calls to wp_redirect to then send back the AMP-Redirect-To header here:
https://thepostmansknock.boldermail.com is the correct URL.
The form sends the data there, the user is subscribed and then boldermail.com redirects the user to https://thepostmansknock.com/welcome-to-the-blog-list/. The process works fine on non-AMP pages -- see the form on the sidebar on https://thepostmansknock.com/blog/
So there would not be any call to wp_redirect.
OK, the response from https://thepostmansknock.boldermail.com will need to send a AMP-Redirect-To response header to redirect the AMP page. More information at https://amp.dev/documentation/components/amp-form/?format=websites#redirecting-after-a-submission
Ok, that makes sense!
I just took a quick look at what the AMP for WordPress plugin does with forms. In one of their extensions, AMP Opt-in, they provide a form builder for 25 different companies (Mailchimp, Mailerlite, etc.) that redirects all actions to an AJAX request within the plugin. Then, the AJAX function actually submits the information to these companies. I think I'll have to implement something like this.
Thanks for your help!
Yes, implementing a proxy endpoint would work if you can't add the AMP-Redirect-To response header to the existing endpoint. Such a proxy endpoint could be built into the Genesis eNews Extended plugin.
Actually I wonder if this proxy would make sense to be built directly into the AMP plugin. This would make the form submissions much less likely to fail, such as when sites don't use wp_redirect() or send requests off to other domains. My only concern here is guarding against abuse. We'd need to make sure that the proxy is not used as a mechanism to do attacks.
Submitting a form to an external URL to subscribe a user and then redirecting them back is something a lot of companies do (like Mailchimp). I have used the Genesis eNews Extended with Mailchimp before, and that was the process. However, I couldn't find any references to using AMP with a Mailchimp form besides the AMP for WordPress plugin and this gist: https://gist.github.com/pshapiro/3a1f5286ff98abd3bd3d7dbe3b5ff70d
The AMP for WordPress plugin has this proxy as a paid extension.
Okay, let me draft a PR to implement this. Would you test?
Sure!
@chvillanuevap I have a PR for you to test: #4212. See build of ZIP if you don't want to do a build yourself: https://github.com/ampproject/amp-wp/pull/4212#issuecomment-582654024
I have also opened a PR to make Genesis eNews Extended AMP-compatible: https://github.com/kraftbj/genesis-enews-extended/pull/146
Sure! I'll test today.
Thanks y'all for your work here. I'll review the PR on the eNews Extended side and get it out.
Hi All - I have a similar commenting issue on my site, which uses the native _Wordpress Twenty Fifteen_ theme and the _AMP Plugin_.
Website: https://www.darrenhuang.com/2020/03/seo-newsletter-issue-4.html

I was about to submit a new issue but noticed this thread and decided to address it here. Is it the same issue and will be fixed in the same pull request? Thank you!
@DarrenHuangTW Hey. The issue you have may be resolved by this, but there is another existing solution. Namely, the problem is that your server has in place strict Mod Security rules which reject requests that contain the query string parameter __amp_source_origin. The HTTP response when submitting the form on your site has:
This has been reported before:
This was resolved by contacting the host to add the __amp_source_origin query param to the allowlist.
@westonruter Thank you for answering so quickly! I'll reach out to Bluehost to resolve it. :-)
Another support topic about this issue: https://wordpress.org/support/topic/new-user-egisteration-getting-failed-in-standard-mode-of-amp/
What are the plans to merge this into the plugin? I just updated to version 1.5.5 because the version I downloaded initially (1.5.0-alpha-20200205T225235Z-b246797c6) was breaking the display of posts for logged in users.
It's currently milestoned for v2.1. So hopefully in a couple months.
This is also needed by the Revue widget in Jetpack: https://github.com/Automattic/jetpack/issues/16922.
Also let's make sure it accounts for the PayPal payment snippet code: https://wordpress.stackexchange.com/questions/367201/amp-and-paypal-form-cors-issue