function doPost(e) { let ss = SpreadsheetApp.openById("123123asdasd"); // Change "SpreadsheetAppId" to your actual sheet id let sheet = ss.getSheetByName("Sheet1"); // Change "Sheet1" to your actual sheet name let data; try { data = JSON.parse(e.postData.contents); } catch (err) { data = e.parameter; } sheet.appendRow([data.fname, data.email, data.message]); return ContentService.createTextOutput("Success").setMimeType(ContentService.MimeType.TEXT); }
说明:
函数 doPost(e)
let ss = SpreadsheetApp.openById("123123asdasd");
varsheet = ss.getSheetByName("Sheet1");
尝试{ data = JSON.parse(e.postData.contents); } catch (err) { data = e.parameter; }
sheet.appendRow([data.fname, data.email, data.message]);
return ContentService.createTextOutput("成功").setMimeType(ContentService.MimeType.TEXT);
4。将脚本部署为 Web 应用程序
5。用于向 Google Apps 脚本 Web 应用程序提交表单数据的 PHP 代码
HTML 代码:
PHP 代码:
$_POST['name'], 'email' => $_POST['email'], 'message' => $_POST['message'], ); $ch = curl_init($url); $postFields = http_build_query($postData); curl_setopt($ch, CURLOPT_POST, 1); // Send a POST request curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); // Attach the POST fields curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string $response = curl_exec($ch); if ($response === false) { $error = curl_error($ch); echo "cURL error: $error"; } else { echo "Server response: $response"; } curl_close($ch); } ?>
以上是如何将 Google 表格与 PHP 网站表单集成:分步指南的详细内容。更多信息请关注PHP中文网其他相关文章!