我正在尝试使用Javascript / jQuery Hands On Table从输入中获取客户端数据并将其传递到服务器端;通过写入文本或.csv文件。
我正在尝试创建的过程如下:
Var Data 是表数据所在的位置。我不知道如何将变量数据传递给像php这样的东西,以便我可以将它作为简单的txt或.csv文件写入服务器。有没有办法调出变量并存储它以便可以写出来?
如何让提交按钮知道将var数据中的数据推送到脚本之外的变量?
我已经阅读了几个教程,脚本和示例,但大多数都解释了如何加载而不是保存数据。一个明确的答案将是感激的。谢谢你提前。
以下是代码:
<!-- Hands On Table -->
<div id="dataTable"></div>
<script>
// Conditional Formatting
function firstRowRenderer(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.style.fontWeight = 'bold';
td.style.color = 'green';
td.style.background = '#CEC';
}
// End of Conditional Formatting
var data = [
["", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", ""]
];
$("#dataTable").handsontable({
data: data,
startRows: 9,
startCols: 9,
minRows: 9,
minCols: 9,
minSpareRows: 1,
removeRowPlugin: true,
outsideClickDeselects: true,
columnSorting: true,
contextMenu: true,
colHeaders: ["RUSH Required", "Rush Date", "Parent ISBN", "e ISBN", "Publisher", "Title", "Conversion Request Type", "Notes/Error Details", "Correction Category"],
columns: [
{
type: 'autocomplete',
source: ["YES", "NO"],
strict: true // Rush Required
},
{
type: 'date',
dateFormat: 'mm/dd/yy'}, // Rush Date
{
type: 'numeric' //Parent ISBN
},
{
type: 'numeric' // e ISBN
},
{
// Publisher
},
{
},
{
// Conversion Request Type
},
{
// Notes / Error Details
},
{
type: 'autocomplete',
source: ["1: Text converted/placed incorrectly", "2: Images converted/placed incorrectly", "3: Special Instructions not followed by vendor", "4: Converted correctly - Publisher unhappy with layout/other"],
strict: true // Correction Category
}
]
})
</script>
<br>
<button id="submit">Submit Request</button>
<!-- End of Hands On Table -->
我最初的计划是使用一个简单的html表单和php写出类似的内容:
<!DOCTYPE html>
<html>
<body>
<h1>Form</h1>
<form name="form1" method="post" action="signup.php"> Username:
<input type="text" name="user">
<br>Email:
<input type="text" name="mail">
<br>Experience:
<select name="exp">
<option value="beginner">Beginner</option>
<option value="intermediate">Intermediate</option>
<option value="advanced">Advanced</option>
</select>
<br>
<input type="submit" name="Submit" value="Sign Up">
</form>
</body>
</html>
和php:
<?php
$username = $_POST['user'];
$email = $_POST['mail'];
$experience = $_POST['exp'];
//the data
$data = "$username | $email | $experience\n";
//open the file and choose the mode
$fh = fopen("users.txt", "a");
fwrite($fh, $data);
//close the file
fclose($fh);
print "Submitted";
?>
正如你所看到的情况变得更加复杂......