-
Notifications
You must be signed in to change notification settings - Fork 383
Creating Forms That Submit POST Requests
Here are some requirements for using a <form method="post">
. See the AMP documentation for more details.
-
The action-xhr attribute is required in order to submit a POST request. The form will then use XHR, without a page refresh. This enables using a template or an amp-live-list to display the response.
-
In the back-end handler for this request, you may use wp_send_json(), or a function that calls that. Like wp_send_json_success() (example).
-
Otherwise, call wp_redirect() at the end of the back-end handler. The plugin will intercept the redirect, add response headers, and call wp_send_json_success().
-
There's no need to enqueue the required amp-form script, as this plugin will do that when it finds a
<form>
. The same applies to all components.
Notice: Please also see the plugin documentation on amp-wp.org