I'm trying to use the Javascript/jQuery Hands On Table to take client side data from their input and pass it through to the server side; either by writing to a text or .csv file.
The process I'm trying to create goes as follows:
- Data Entered into Hands On Table (JS)
- Submit data with html submit button (post method)
- Submit button calls the var array data to pass to the server (?php, ajax, json?)
Var Data is where the table data is located. I am not sure how to pass the variable data to something such as php, so that I can then write it to the server as a simple txt or .csv file. Is there a way to call out the variable and store it so that it may be written out?
How would I cause the submit button to know to push the data from var data to a variable outside of the script?
I've read several tutorials, scripts, and examples but most of them explain how to load and not save the data. A clear answer would be grateful. Thanks in advanced.
Here is the code:
<!-- 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 -->
My original plan was to use a simple html form and php to write out similar to this:
<!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>
and the 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";
?>
As you can see the situation became a lot more complex...