Skip to content

Add automatic support for handling form POST post submissions that redirect #911

@westonruter

Description

@westonruter

All AMP post forms use XHR to submit the request. When we sanitize a form (#907) to upgrade a form[method=post][action=/foo] to form[method=post][action-xhr=/foo], we also need to make sure that the result of the form being submitted is handled as well. In particular, when we rewrite an action to an action-xhr we should add a query var to the URL like _wp_amp_action_xhr_converted=1(e.g. the action here could get sanitized to be /foo?_wp_amp_action_xhr_converted=1) so that when WP calls wp_redirect() we can hook into it and automatically sent the AMP-Redirect-To and Access-Control-Expose-Headers headers instead: https://www.ampproject.org/docs/reference/components/amp-form#redirecting-after-a-submission

Otherwise, if the action-xhr attribute was supplied to begin with, then no such redirect interception would be done, as then it would be assumed that the theme/plugin is already properly handling the XHR request client-side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions