这是我用来向 3rd 方服务 (JotForm) 提交 AMP 表单的 PHP 脚本:
<?php
if (!empty($_POST)) {
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:".$_SERVER['HTTP_ORIGIN']);
header("access-control-expose-headers:AMP-Access-Control-Allow-Source-Origin");
// change to represent your site's protocol, either http or https
header("amp-access-control-allow-source-origin:https://".$_SERVER['HTTP_HOST']);
header("Content-Type: application/json");
$firstName = isset($_POST['first_name']) ? $_POST['first_name'] : '';
$lastName = isset($_POST['last_name']) ? $_POST['last_name'] : '';
$phone = isset($_POST['your_phone_number']) ? $_POST['your_phone_number'] : '';
$email = isset($_POST['your_email']) ? $_POST['your_email'] : '';
$city = isset($_POST['driver_app_request_call_hiring_city']) ? $_POST['driver_app_request_call_hiring_city'] : '';
try {
include "JotForm.php";
$jotformAPI = new JotForm("APIkey");
$submission = array(
"3" => $firstName,
"4" => $lastName,
"5" => $phone,
"6" => $email,
"7" => $city
);
$result = $jotformAPI->createFormSubmission("formId", $submission);
$output = ['message' => "Your application was submitted. Thank you!"];
header("Content-Type: application/json");
echo json_encode($output);
} catch (Exception $e) {
var_dump($e->getMessage());
}
}
?>
对我们来说效果很好!