Skip to content

Instantly share code, notes, and snippets.

@alexandr-kazakov
Created November 27, 2017 08:54
Show Gist options
  • Save alexandr-kazakov/f0529503ec09bb8415a0af5571de3906 to your computer and use it in GitHub Desktop.
Save alexandr-kazakov/f0529503ec09bb8415a0af5571de3906 to your computer and use it in GitHub Desktop.
== HTML ============================================================
<!doctype html>
<html amp lang="ru">
<head>
<title>Тестовая форма AMP</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link rel="canonical" href="/index.html">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<!-- begin Подключаем для форм нужные скрипты -->
<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>
<!-- end Подключаем для форм нужные скрипты --><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> </head>
<body>
<h1>Пример формы AMP для файла PHP</h1>
<p>Текст отправляется формой AMP в файл PHP, который возвращает ответ в формате JSON.</p>
<form method="post" action-xhr="amp-mail.php" target="_top" class="amp-form-php">
<div class="amp-form-php__item">
<label>Введите текст:
<input type="text" name="name" value="" required> </label>
</div>
<div class="amp-form-php__item">
<input type="submit" value="Envoyer"> </div>
<div submit-success>
<template type="amp-mustache">Текст, возвращаемый PHP: {{name}}</template>
</div>
<div submit-error>
<template type="amp-mustache">Ошибка!</template>
</div>
</form>
</body>
</html>
== PHP =====================================================================
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: https://' . $_SERVER['HTTP_HOST']);
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin');
header('AMP-Access-Control-Allow-Source-Origin: https://' . $_SERVER['HTTP_HOST']);
$data = array();
$data['name'] = $_POST['name'];
echo json_encode($data);
?>
@mgunalp
Copy link

mgunalp commented Dec 5, 2017

hi,
this code have classic asp
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: https://' . $_SERVER['HTTP_HOST']);
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin');
header('AMP-Access-Control-Allow-Source-Origin: https://' . $_SERVER['HTTP_HOST']);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment