1

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:

  1. Data Entered into Hands On Table (JS)
  2. Submit data with html submit button (post method)
  3. 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...

Mark
  • 150
  • 1
  • 8
  • This will be helpful: http://stackoverflow.com/questions/20150130/ajax-and-php-to-enter-multiple-forms-input-to-database/20150474#20150474 – MonkeyZeus Feb 21 '14 at 21:37
  • And when you go to debug: http://stackoverflow.com/a/21617685/2191572 – MonkeyZeus Feb 21 '14 at 21:37
  • Using your system, it is very easy to inject a lot of bad data. Why not use a proper format such as JSON (if you must use text at all)? Or if you are going with delimiters, you must have something to escape them. – Brad Feb 21 '14 at 21:48
  • @Brad your right, I failed to mention I am going to go back and enter security/validation code later, but wanted the overall idea figured out first. Also, this will be for internal use and security isn't a huge concern at the moment. Thank you for the lead will check into it. – Mark Feb 21 '14 at 21:53
  • This isn't necessarily a security problem, but a broken data problem. Suppose someone uses a pipe or new line in their "experience". Plus, all the work you have to go through to parse a format you invented when a simple `json_encode()` and `json_decode()` (or similar) would work just fine. – Brad Feb 21 '14 at 22:01

0 Answers0