1
votes

I am getting these errors in the browser

"Response must contain the AMP-Access-Control-Allow-Source-Origin header"

and

"Form submission failed: Error: Response must contain the AMP-Access-Control-Allow-Source-Origin header​​​"

php

<?php
if (isset($_POST['iletisimg'])) {
    $status = 0;
    $ip = $_SERVER['REMOTE_ADDR'];
    $time = time();
    if (empty($post->isim) || empty($post->mesaj) || empty($post->email)) {
        $yorumcevap = "Lütfen tüm alanları eksiksiz doldurunuz!";
    } else {
        $yorumekle = $db->query("insert into iletisim (isim,mesaj,email,konu,durum,tarih,ip) values ('$post->isim', '$post->mesaj', '$post->email', '$post->konu', 0, '$time', '$ip')");
        if ($yorumekle) {
            $yorumcevapok = "Teşekkürler. Talebiniz alındı.";
        } else {
            $yorumcevap = "Hata! Lütfen tekrar deneyin.";
        }
    }
}

html

<html amp lang="tr">
<head>
    <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>
</head>
<body>
<form method="post" action-xhr="#" autocomplete="off">
    <?PHP echo '<p>' . $yorumcevap . '</p>'; ?>
    <input type="text" class="isim" name="isim" autofocus required>
    <input type="text" class="isim" name="konu" required>
    <input type="text" class="isim" name="email" required>
    <textarea name="mesaj" cols="80" rows="8" required></textarea>
    <input type="submit" value="Gönder" name="iletisimg">
</form>
</body>
</html>

How can I edit it this to avoid those errors ?

1

1 Answers

0
votes

You need to ensure that your CORS settings meet the AMP requirements as documented here

There's also a similar question which provides the code on how to set the response headers properly: AMP Access Control Allow Source Origin header Issue