如何在提交时将amp表单重定向到另一个页面?

时间:2018-10-12 13:04:20

标签: amp-html amphp

下面提到的代码是我的表单代码

<form class="contact100-form validate-form" method="post" action-xhr="https://www.aptadvantage.com/popup_2.php">
   <div class="wrap-input100 validate-input" data-validate="Name is required">
      <input class="input100" id="name" type="text" name="name" placeholder="Your Name" required>
   </div>
   <div class="wrap-input100 validate-input" data-validate="Phone is required">
      <input class="input100" id="phone" type="number" name="phone" placeholder="Your Number" required>
   </div>
   <div class="wrap-input100 validate-input">
      <select name="course" class="input100 label-input100" style="background: #fff;color: #909090;outline:0;" required>
         <option value="">Choose Your Course</option>
         <option value="NOT DECIDED">NOT DECIDED</option>
         <option value="DIPLOMA IN ADVANCE SERVICE MANAGEMENT">DIPLOMA IN ADVANCE SERVICE MANAGEMENT</option>
         <option value="DIPLOMA IN CABIN CREW TRAINING">DIPLOMA IN CABIN CREW TRAINING</option>
         <option value="DIPLOMA IN AIRPORT &amp; TRAVEL MANAGEMENT">DIPLOMA IN AIRPORT &amp; TRAVEL MANAGEMENT</option>
         <option value="DIPLOMA IN HOTEL OPERATION &amp; TRAVEL MANAGEMENT">DIPLOMA IN HOTEL OPERATION &amp; TRAVEL MANAGEMENT</option>
      </select>
   </div>
   <div class="container-contact100-form-btn pt3">
      <div class="wrap-contact100-form-btn">
         <div class="contact100-form-bgbtn"></div>
         <input class="button center submit_btn" type="submit" value="SUBMIT" style="color: #fff;width: 90%;margin: 30px auto; display: block;">
      </div>
   </div>
</form> 

下面提到的代码是我用于上述表单的php代码。

<?php
if(!empty($_POST)){
$email = "test@test.com";
$name = $_POST['name'];
$course = $_POST['course'];
$phone = $_POST['phone'];
$enquiry = $_POST['enquiry'];
$formcontent=" From: $name \n Phone: $phone \n Course: $course";
$recipient = "test@test.com";
$subject = 'KNOW YOUR DISCOUNTED FEES FORM FROM HOME PAGE';
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

       $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-Headers:Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token");
        // header("Access-Control-Allow-Methods:POST, GET, OPTIONS");
        header("Access-Control-Allow-Origin: ". str_replace('.', '-','http://fleapo.co/apt/') .".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://www.aptadvantage.com");
        header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin, AMP-Redirect-To");
        header('Location: https://www.aptadvantage.com');
        echo json_encode(array('name' => $name));
        exit;
}
?>

我面临的基本问题是,在提交表单时,页面应重定向到其他页面,但不会发生。我希望将提交时的表单重定向到另一个页面,但是该页面保持原样。我收到在表格中输入的详细信息。将页面重定向到另一个页面所需的代码已经存在,但仍然无法正常工作。任何成员的任何帮助对我来说都是非常有益的。感谢您阅读全文。感谢您的宝贵意见。

1 个答案:

答案 0 :(得分:0)

响应的标题中存在与“ Access-Control-Allow-Origin”有关的问题。出现此错误的原因是,显示表单的页面和发送数据的服务器位于不同的域中。确保两者都在同一个域中。 服务器上的“ Access-Control-Allow-Origin”设置为“ http://fleapo-co/apt/.cdn.ampproject.org”。它在这里制造问题。

如果您要在其他域中显示表单并将请求发送到其他域,而不是将“ Access-Control-Allow-Origin”设置为“ *”或“您要发送的域” -a-POST方法”。设置好之后,您的表单和重定向即可使用。