The POST action is being passed but POST data is empty after client edit

The POST action is being passed but POST data is empty after client edit

glenbensonglenbenson Posts: 2Questions: 2Answers: 0
edited May 2023 in Free community support

I need to write the backend in Java (Tomcat) I am using the datatables editor demo code to get up and running . After an edit (save on blur) I need to pass the data to my own code.
To test I'm using a simple php code to look at the data.
Here is that code

<?php
$input_data = $_POST;
// Collect all of the POST data and werite to a file dtepost.txt.
foreach ($_POST as $key => $value) {
     $x = htmlspecialchars($key)." = ".htmlspecialchars($value)."\n";
     file_put_contents("dtepost.txt", $x,FILE_APPEND);
 }
// I return this so it doesnt crash the client just for testing
echo "{\"data\":[{\"DT_RowId\":\"row_29\",\"first_name\":\"Fiona\",\"last_name\":\"Green\",\"position\":\"Chief Operating Officer (COO)\",\"email\":\"f.green@datatables.net\",\"office\":\"San Franciscodsfsdf\",\"extn\":\"2947\",\"age\":\"48\",\"salary\":\"850000\",\"start_date\":\"2010-03-11\"}],\"debug\":[\"xx\"]}";

<?php
>
```
?>


This is the contents of the file dtepost.txt 

data =
action = edit


There is no data received BUT I did get the action. ```js /* Here is the chunk of the client code */ var editor; // use a global for the submit and return data rendering in the examples $(document).ready(function() { editor = new $.fn.dataTable.Editor({ ajax: { "url": "dte.php", "type": 'POST', success: function(data) { console.log(data); } }, table: "#example", fields: [{ label: "First name:", name: "first_name" }, { label: "Last name:", name: "last_name" }, { label: "Position:", name: "position" }, { label: "Office:", name: "office" }, { label: "Extension:", name: "extn" }, { label: "Start date:", name: "start_date", type: "datetime" }, { label: "Salary:", name: "salary" } ] });

Is the row data passed as a POST from the submitted form or some other way.

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    data, as posted is an object. htmlspecialchars expects a string - hence the issue.

    What you could do is:

    $x = print_r($_POST, true);
    file_put_contents("dtepost.txt", $x,FILE_APPEND);
    // note - no need for the `for` loop
    

    Which uses print_r to dump the value.

    Unusual to be writing PHP for a Java backend though ;-).

    The client / server data interchange for Editor is documented in the manual, and the examples all show the data submitted / received if you click the last table below the table.

    Allan

Sign In or Register to comment.