私はReference Linkを使用してAMPニュースレターの購読フォームを実装しようとしています。AMPニュースレターフォームレスポンス号
サーバーサイドスクリプト::
<?php
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");
$data = array('name'=>$_POST['name'],'email'=>$_POST['email']);
echo json_encode($data);exit;
?>
AMP FORM HTML
<form method="post"
class="p2"
action-xhr="https://www.example.com/request.php"
target="_top">
<div class="ampstart-input inline-block relative m0 p0 mb3">
<input type="text"
class="block border-none p0 m0"
name="name"
placeholder="Name..."
required>
<input type="email"
class="block border-none p0 m0"
name="email"
placeholder="Email..."
required>
</div>
<input type="submit"
value="Subscribe"
class="ampstart-btn caps">
<div submit-success>
<template type="amp-mustache">
Success! Thanks {{name}} for trying the
<code>amp-form</code> demo! Try to insert the word "error" as a name input in the form to see how
<code>amp-form</code> handles errors.
</template>
</div>
<div submit-error>
<template type="amp-mustache">
Error! Thanks {{name}} for trying the
<code>amp-form</code> demo with an error response.
</template>
</div>
</form>
フォームは私が要求を処理し、応答を返すために、次のコードを使用して、サーバー側で、送信されるとリクエストが完了するとそれは、常に私のHTMLフォームテンプレートのsubmit-success
一部が表示されます。私の主な質問は、name
の返信で上記のフォームのsubmit-error
部分を表示する方法と、サーバー側で要求を処理して、それぞれsuccess
またはerror
メッセージを表示する方法は何ですか?
で3210 UPDATE
次の行を置き換え
ありがとう@SebastianBenz!私に4XXまたは5XXすなわちエラーステータスのためのヒントを与えます。しかし私はドキュメントを読んだが、私は理解できなかった。しかし、今は明らかです。ありがとう+1) –