我有一个表单,您可以选择一个日期范围(#StartDate - #EndDate 或 #AllDates),它将数据写入 .csv 文件并强制下载。无论出于何种原因,我都无法传递 #StartDate 和 #EndDate 值。它们是由 glDatePicker 字段生成的,但即使我输入硬编码值,它们也不会被传递。我运行 $('#StartDate').val(); 在控制台中并返回日期,但是当我取消注释时
var_dump($_POST);
它返回一个空数组。后端脚本正在使用:
`FuncitionNameHere(trim($_POST["AllDates"]), trim($_POST["StartDate"]), trim($_POST["EndDate"]))`
相关部分是
<form action="path/to/curl.php" method="post" id="Form6">
<ul>
<li>
<label for="StartDate">Start Date</label>
<input type="text" id="StartDate" name="StartDate" />
</li>
<li>
<label for="EndDate">End Date</label>
<input type="text" id="EndDate" name="EndDate" />
<input type="submit" id="Button6" value="Send" />
</li>
<li>
<label for="AllDates"><input type="checkbox" name="AllDates" id="AllDates" value="YES"> All Dates</label>
</li>
</ul>
</form>
以及将数据发送到远程数据库的 curl 脚本
<?php
session_start();
$url = 'https://remoteurl.com';
$StartDate = $_POST["StartDate"];
$EndDate = $_POST["EndDate"];
$AllDates = $_POST["AllDates"];
$fields = array(
'StartDate'=>urldecode($StartDate),
'EndDate'=>urldecode($EndDate),
'AllDates'=>urldecode($AllDates)
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string,'& ');
//var_dump($_POST);
$ch = curl_init($url);
session_write_close();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$directory='/home/XXX/public_html/XXX/';
$filename = 'Report.csv';
$handle = fopen($directory.$filename, 'w');
fwrite($handle, $output);
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="Report.csv"');
echo $output;
?>
发布#AllDates 但没有发布#StartDate 或#EndDate 值的任何明显原因?