简体   繁体   English

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

[英]How to redirect amp form on submission to another page?

Below mentioned code is my form code 下面提到的代码是我的表单代码

<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> 

Below mentioned code is my php code for the above 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;
}
?>

The basic issue which I am facing is that on submitting the form the page should redirect to another page which doesn't happen. 我面临的基本问题是,在提交表单时,页面应重定向到其他页面,但不会发生。 I want my form on submit to be redirected to another page but instead the page remains as it is. 我希望将提交时的表单重定向到另一个页面,但是该页面保持原样。 I am recieving the details which have been entered in the form. 我收到在表格中输入的详细信息。 The code which was required to redirect the page to another page is already present but still it doesn't work. 将页面重定向到另一个页面所需的代码已经存在,但仍然无法正常工作。 Any help from anyone of the members will be very fruitful to me. 任何成员的任何帮助对我来说都是非常有益的。 Thanks for reading til the end. 感谢您阅读全文。 Thanks for advance for any suggestions from your side. 感谢您提供的任何建议。

There is an issue regarding "Access-Control-Allow-Origin" in your header of the response. 响应的标题中存在与“ Access-Control-Allow-Origin”有关的问题。 This error is coming because the page where the form is displayed and the server where it sends the data are in different domain. 出现此错误的原因是,显示表单的页面和发送数据的服务器位于不同的域中。 Make sure both are in same domain. 确保两者都在同一个域中。 Your "Access-Control-Allow-Origin" on the server is set to " http://fleapo-co/apt/.cdn.ampproject.org ". 服务器上的“ Access-Control-Allow-Origin”设置为“ http://fleapo-co/apt/.cdn.ampproject.org ”。 It is creating issue over here. 它在这里制造问题。

And if you want to display the form in different domain and send request to other domain than set "Access-Control-Allow-Origin" to "*" or "domain-from-you-are-going-to-request-a-POST-method". 并且,如果您想在其他域中显示表单并将请求发送到其他域,而不是将“ Access-Control-Allow-Origin”设置为“ *”或“ domain-from-you-going-to-request-a- POST方法”。 Once you set that, your form and redirection will work. 设置好之后,您的表单和重定向即可使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM