我在填写表单后创建了一个AMP表单,它应该重定向到感谢页面:
<form on="tap:my-lightbox" custom-validation-reporting="show-all-on-submit" action-xhr="https://example.com/amp/nextown/test.php" method="post" target="_blank" role="form">
<div class="col-md-12">
<input type="text" class="form-control" name="name" id="lblname" placeholder="Name*" required pattern="\w+\s\w+">
<span visible-when-invalid="valueMissing" validation-for="lblname"></span>
<span visible-when-invalid="patternMismatch" validation-for="lblname">
</span>
</div>
<div class="col-md-12">
<input type="email" class="form-control" name="email" id="lblemail" placeholder="Email Address*" required="text">
<span visible-when-invalid="valueMissing" validation-for="lblemail"></span>
<span visible-when-invalid="typeMismatch" validation-for="lblemail"></span>
</div>
<div class="col-md-12">
<input type="text" class="form-control" name="phone" id="lblphone" placeholder=" Phone Number*" required="text"></div>
<div class="col-md-12 but-mdsubmit">
<input id="popup_sub" type="submit" value="SEND ENQUIRY" >
</div>
</div>
</form>
test.php 代码:
$domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
$redirect_url = 'https://example.com/amp/nextown/thankyou.amp.html';
if($_POST['name']!="" && $_POST['email']!="" && $_POST['phone']!=""){
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['phone'];
$source= "NA";
$medium = "NA";
$campaign = "NA";
$vserv= "NA";
$state="NA";
$city = "NA";
$dialing_code='91';
$country='India';
$project_id ='284';
$client_id ='4';
$ind_project_id='';
$crm_url = "http://exampleapi.com/campaign/fetch_data/".urlencode($name)."/".urlencode($email)."/".urlencode($mobile)."/284/".urlencode($source)."/".urlencode($medium)."/".urlencode($campaign)."/4/NA/NA/".urlencode($dialing_code)."";
if(file_get_contents($crm_url)){
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://netbizlabs.com");
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin, AMP-Redirect-To");
header ('AMP-Redirect-To: '.$redirect_url);
//echo json_encode(array('successmsg'=>'My success message. [It will be displayed shortly(!) if with redirect]'));
exit;
}
}
但它不是重定向,我做错了请帮助我,因为我是AMP网站开发的新手。
提前致谢。
答案 0 :(得分:0)
替换条件代码
if(file_get_contents($crm_url)){
$domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
header("Content-type: application/json");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: ". str_replace('.', '-','https://netbizlabs.com') .".cdn.ampproject.org");
header("AMP-Access-Control-Allow-Source-Origin: " . $domain_url);
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
header("AMP-Redirect-To: https://example.com/amp/nextown/thankyou.amp.html");
header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin");
echo json_encode(array('successmsg'=>'data post'));
exit;
}