我一直在试图创建一个使用AMP-HTML用PHP接触形式的接触形式。我只是无法让它工作。当我点击按钮时,错误信息从amp-mustache模板(但没有名称字段)显示 - 但我看不到实际的错误。创建使用AMP-HTML与PHP
我一直在看放大器的文档和这个问题,但不能它的工作。 AMP form submitting with post。我用这个作为我的代码的基础,我无法实现它的工作。我已将成功模板移入表单并添加了错误模板。也许我应该对这个问题进行评论,但由于它有一个可以接受的答案,而且我仍然有问题,所以我想我应该提出一个新问题。
我与HTTP尝试了一段时间,但现在意识到我需要使用https所以我试图与此域,但没有运气。
我的代码除了域名外如下。
<?php
if(isset($_POST['submitlogin']))
{
$name = isset($_POST['name']) ? $_POST['name'] : '' ;
$output = [
'name' => $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.example.com");
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
echo json_encode($output);
die();
}
?>
<!doctype html>
<html amp>
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="canonical" href="https://www.example.com/test.php"/>
<title>AMP form</title>
</head>
<body>
<form method="post" action-xhr="#" target="_top">
Name:<input type="text" name="name" />
<input type="submit" name="submitlogin" value="Submit" />
<div submit-success>
<template type="amp-mustache">
Success! Thanks for trying the
<code>amp-form</code> demo! The name submitted was {{name}}
</template>
</div>
<div submit-error>
<template type="amp-mustache">
Error! Thanks {{name}} for trying
</template>
</div>
</form>
</body>
</html>
一旦我知道这个简单的表单工作,我实际上可以完成联系人部分并发送电子邮件。
我错过了什么?
谢谢
的[AMP形式与交提交]可能的复制(http://stackoverflow.com/questions/41346187/amp-form-submitting-with-post) –