epiz_28063674
I am having an issue with code showing up from a .php page rather than executing.
Brief Background:
I wish to use amp-forms in AMPHTML which is somewhat unfamiliar. Using amp-form requires CORS permissions to work. I have created a couple of sandbox files to transfer data in a GET request from my .html page to the .php page. Thus far this works and I have managed to verify the data will pass when using method=“POST” where it shoots back to the the original page. I would like to move the data forward in a product checkout application. Using GET, I also have no CORS errors but any code below the header statements just prints out in the browser without executing.
The two files are here
michaelsbookcorner.com/getformTest.html
michaelsbookcorner.com/getbookSubmit.php
<!doctype html>
<html amp lang = "en">
<head>
<meta charset = "utf-8">
<script async src = "https://cdn.ampproject.org/v0.js">
</script>
<title>AMP - Book Submit Form</title>
<link rel = "canonical" href = "ampform.html">
<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>
<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.2.js">
</script>
<script async custom-element="amp-selector"
src="https://cdn.ampproject.org/v0/amp-selector-0.1.js">
</script>
<style amp-custom>
form.amp-form-submit-success [submit-success],
form.amp-form-submit-error [submit-error]{
margin-top: 16px;
}
form.amp-form-submit-success [submit-success] {
color: white;
background-color:gray;
}
form.amp-form-submit-error [submit-error] {
color: red;
}
form.amp-form-submit-success.hide-inputs > input {
display: none;
}
ul {
list-style: outside none none;
}
div.books {
width: 90%;
height: 80px;
margin-top: 10px;
}
amp-selecter {
width: 100%;
padding: 10px 15px;
border: 1px dashed blue;
border-radius: 4px;
background-color: orange;
}
.center {
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div id="bookFormats" class="container center">
<h2 class="center italic"><b>Purchase</br>The Gifted: A Positive Tale of Mutation</b></h2>
<form
method = "get"
class = "p2"
action = "getbookSubmit.php">
<p>AMP - Form Example</p>
<div class="books" >
<amp-img src="https://res.cloudinary.com/michaelsbookcorner/image/upload/v1641072491/BookstoreImages/AgesWebCover1000x1500_yeugrh.jpg" width="50" height="75"></amp-img>
<input type="hidden" name="catalog" value="bk_003_0">
<p>Choose your format.</p>
<amp-selector id="format" layout="container" name="format">
<ul>
<li>
<div class="books" option="_epub" selected>
<amp-img src="I-Images/EbookIcon100px.png" width="75" height="75"></amp-img>
.epub (most readers)</div>
</li>
<li>
<div class="books" option="_mobi">
<amp-img src="I-Images/KindleLogo.png" width="75" height="75"></amp-img>
.mobi (Kindle)</div>
<li>
<div class="books" option="_audio">
<amp-img src="I-Images/AudiobookIcon100px.png" width="75" height="75"></amp-img>
.audio (.mp3/.zip)</div>
</li>
</ul>
<br/>
<br/>
<input
type = "email"
name = "email"
placeholder = "Enter Email"
required>
<br/>
<br/>
<input type = "submit" value = "Submit">
</form>
</div>
</body>
</html>
<?php
ini_set('session.use_cookies', '0');
ini_set('session.use_only_cookies',0);
ini_set('session.use_trans_sid',1);
session_start();
if(!empty($_GET)){
$domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") .
"://$_SERVER[HTTP_HOST]";
header("Content-type: application/json");
header("AMP-Access-Control-Allow-Source-Origin: " . $domain_url);
header("Access-Control-Expose-Headers:
AMP-Access-Control-Allow-Source-Origin");
$_SESSION['catalog'] = $_GET['catalog'].$_GET['format'];
$_SESSION['email'] = $_GET['email'];
// Get PHPSESSIONID and pass it with successEmail.php url
$getstring = htmlspecialchars(SID);
echo '
<a id="finish" href="orderConfirm.php?'.$getstring.'">Confirm</a>';
// Invoke JavaSCript to automattically 'click' the sending link
echo '
<script type="text/javascript">
document.getElementById("finish").click();
</script>';
}
?>