Using forms in AMP
Before we start building forms, let's get the basics out of the way. The first thing to know is that whenever any form is used in an AMP page, then the amp-form
extension script must also be included:
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
Submitting forms in AMP
Forms in AMP can be submitted as full page GET requests, or as XHR (or AJAX) GET or POST requests:
- If you use
method="GET"
in your form, you must then define a submission endpoint in either theaction
oraction-xhr
attribute - If you use
method="POST"
then you must only useaction-xhr
for your submission endpoint - Endpoints must be served on an HTTPS URL, and must not link to the AMP cache CDN
- Finally, you must also include the
target
attribute, and it can have a value of either_blank
(opens in new window) or_top
(opens in current window)
Note
The following inputs are not permitted: <input type=button>
, <input type=file>
, <input type...