2013年自定义Google表单中的Google文档表格Formkey

时间:2013-02-06 07:58:14

标签: php web

您好我正在尝试开发一个CURL PHP,首先通过PHP发送我的Google表单,然后重定向到目标网页。但是,我的问题在于旧的Google Formkey响应。

在您可以查看表单源之前,它将具有一个formkey ID号,您可以轻松地将其插入到PHP脚本中。

这是我的脚本示例:

//Google Form Key
$formkey = "WHERE IS THE FORMKEY";

$thankyou = "http://www.eksenaevents.com/submission-successful/";

//Change this URL to your google form address
$googleformURL = "https://docs.google.com/forms/d/1pCIHFvau8KuR_J1gSAx2weGcdRGjNH0MERdeinbWd-  0/viewform";

//----------------Send Form Fields to Google--------------------
//Loops through the form fields and creates a query string to submit to google
foreach ($_POST as $var => $value) {

if ($var != "ignore") {
$postdata=$postdata . htmlentities(str_replace("_", "." , $var)) . "=" . $value . "&";
}
 } 

//remove the extra comma
$postdata=substr($postdata,0,-1); 

//Submit the form fields to google
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$googleformURL);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;   rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$data = curl_exec ($ch);
curl_close($ch); 
//echo $data;

//Redirect to your thank you page
header( "Location: $thankyou" ) ;

?>

1 个答案:

答案 0 :(得分:0)

我知道那个人可能不会看到这个,但对于其他人,你的表格密钥是。 。 1pCIHFvau8KuR_J1gSAx2weGcdRGjNH0MERdeinbWd

你的谷歌表格网址应该是这样的

https://docs.google.com/yourdomainwhatev/spreadsheet/formResponse?formkey=insert您的表格密钥在这里#gid = 0

如果您打开表单,只需复制网址并删除表单密钥