Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amp-form: pass through non-XHR POST requests #27638

Open
adekbadek opened this issue Apr 8, 2020 · 4 comments
Open

amp-form: pass through non-XHR POST requests #27638

adekbadek opened this issue Apr 8, 2020 · 4 comments

Comments

@adekbadek
Copy link

amp-form throws an error if a form without action-xhr attribute is submitted:

handleNonXhrPost_() {
// non-XHR POST requests are not supported.
userAssert(
false,
'Only XHR based (via action-xhr attribute) submissions are supported ' +
'for POST requests. %s',
this.form_
);
}

There might be a situation where a regular (non-XHR) form is rendered on an AMP page – this form will be unsubmittable.

Would it be possible to allow default form submission for non-XHR forms?

@westonruter
Copy link
Member

Yes, we need this very much.

At present, it is almost impossible to use existing POST forms on AMP pages. For example, if you have a newsletter form for something like Mailchimp which:

  1. Does not send CORS headers.
  2. Does not do any redirect, let alone send AMP-Redirect-To.
  3. Responds with an HTML page and not JSON.

These make such existing form submission endpoints completely incompatible with form[method=post][action-xhr].

For awhile now I've been trying to work out a way to let the AMP plugin automatically support such forms by means of a form submission proxy: ampproject/amp-wp#4191. I even made a prototype mini plugin that implements this proxy, which well in the case of form submissions that do a redirect. However, if the form submission endpoint returns HTML (like Mailchimp does) then it is has to try to hack its way to try to scrape the error/success messages from the HTML page to supply into the div[submit-success] and div[submit-error] templates. Nevertheless, this proxy doesn't always work as I found on a support topic where it appears that Mailchimp is blocking the IP addresses from some shared hosts to prevent abuse.

One other problem that comes up over and over again is that the AMP XHR requests include an __amp_source_origin query parameter. It turns out that ModSecurity appears to block requests with this query parameter by default, resulting in 406 Not Acceptable being returned. See #34615.

All of these headaches would be avoided if AMP would just allow form[method=post][action], bypassing any XHR functionality so that traditional full page navigations in the same way as AMP currently does for form[method=get][action] instances.

I'm not entirely sure why AMP required XHR for POST forms in the first place. Perhaps it was to encourage developers toward Ajax to create better user experiences? If that's the extent of the rationale, then for the sake of ecosystem compatibility and adoption the XHR requirement for POST forms should be made optional: encouraged yet not required.

@stale
Copy link

stale bot commented Jan 21, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Inactive for one year or more label Jan 21, 2023
@xgqfrms
Copy link

xgqfrms commented Aug 15, 2024

@stale stale bot removed the Stale Inactive for one year or more label Aug 15, 2024
@zoolyka
Copy link

zoolyka commented Aug 24, 2024

AMP requires XHR to POST a form, but using it will degrade your INP web vitals scores, since on low-end mobile devices it is really slow by design (it initializes the states, templates, etc. on interaction). Now I want to migrate these XHR's back to regular POST methods to avoid the INP issues and it is not allowed...

Is there any valid solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants