I\'ve a website for years with a few forms to login etc. Recently I made it all Google\'s AMP proof, but the forms stopped working. I\'m searching for days now, but I can\'t
To put it simply: you can't just echo the input.
From the docs:
Use the action-xhr attribute to submit the form via XMLHttpRequest (XHR). You can use amp-mustache templates to show custom success or error messages, using data sent by the server endpoint as JSON. For example, if the server sends {"foo": "bar"}, you can use use {{foo}} in the template to render bar.
So since you are using the action-xhr, you should be returning a JSON, and update the form template accordingly.
Check out this.
Full example, from your code:
$name
];
header("Content-type: application/json");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: *.ampproject.org");
header("AMP-Access-Control-Allow-Source-Origin: https://www.domain.com");
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
echo json_encode($output);
die();
}
?>
AMP form
Success! Thanks for trying the
amp-form
demo! The name submited was {{name}}