###前提・実現したいこと
現在、ローカル環境のhttps通信にてAMPに対応したPHPサイト制作をしており、
amp-formでの問い合わせフォームを作成中です。
メール送信処理が完了したら成功メッセージを、失敗したらエラーメッセージを表示する予定です。
メールの送信処理以前に入力した内容をjson形式で返す処理(contact.php)を作成したのですが、
処理後にsubmit-errorのdivが表示されます。
PHPの処理内容が間違っていると思うのですが、AMPとPHPに詳しい方お教えいただけませんでしょうか?
###発生している問題・エラーメッセージ
Error! ( <div submit-error> の内容が表示される)
###該当のソースコード
html
1<!doctype html> 2<html amp> 3<head> 4 <meta charset="utf-8"> 5 <script async src="https://cdn.ampproject.org/v0.js"></script> 6 <script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script> 7 <script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script> 8 <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> 9 <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> 10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 11 <link rel="canonical" href="https://www.localhost/"/> 12 <title>AMP form</title> 13</head> 14<body> 15<form method="post" action-xhr="https://www.localhost/contact.php" target="_top"> 16 Name:<input type="text" name="name" /> 17 Email:<input type="email" name="email" /> 18 <input type="submit" name="submit" value="Submit" /> 19 <div submit-success> 20 <template type="amp-mustache"> 21 Success! name : {{name}} email: {{email}} 22 </template> 23 </div> 24 <div submit-error> 25 <template type="amp-mustache"> 26 Error! 27 </template> 28 </div> 29</form> 30</body> 31</html>
php
1<?php 2// contact.php 3if(isset($_POST['submit'])) 4{ 5 header('Access-Control-Allow-Credentials: true'); 6 header('Access-Control-Allow-Headers: Content-Type'); 7 header('Access-Control-Allow-Origin: https://www.localhost/'); 8 header('Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin'); 9 header("AMP-Access-Control-Allow-Source-Origin: https://www.localhost/"); 10 header('Content-Type: application/json'); 11 12 //ここにメール送信処理(未実装) 13 14 $json = array( 15 'name'=> $_POST['name'] 16 'email'=> $_POST['email'] 17 ); 18 echo json_encode($json); 19} 20exit(); 21?> 22
###試したこと
AMPのドキュメントやexampleも確認したのですが、英語が苦手な為、解決には至りませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
OpenSSL 1.1
Apache 2.4
PHP 5.6