I am working on an existing static site (only HTML and Javascript) that uses AMP. I need to add a form that submits a POST request to a third party service. The service only accepts POST requests.
When I add the form using normal HTML I get the following error.
Only XHR based (via action-xhr attribute) submissions are support for POST requests.
Doing some research I learned that AMP forms require the action-xhr
attribute. Changing my form's action
attribute to action-xhr
results in this error:
The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'.
Is there a way I can add a form to a site that uses AMP so that the form submits a POST request to a third party URL? Preferably AMP would not interfere at all.
You can manually submit the form by adding onclick="submit()" to your submit button. This will let you Submit the amp-form through the action method on a POST request.
Example: