rolling my own server scripts for use with generator
rolling my own server scripts for use with generator
I'm creating my own php scripts to handle interacting with the database, rather than use the PHP library. I'm getting it worked out, but I'm having trouble parsing the data sent via POST to my script.
To debug this, I'm sending messages to the javascript console using ChromeLogger. In my code, you'll see these as calls to my function fb() which calls ChromeLogger.
Here is my editor definition. Note that $.urlParam is a function to extract a url parameter when this is called. This parameter is the ID of a parent record, and this is the reason I'm writing my own code for this.
var editor = new $.fn.dataTable.Editor( {
ajax: {
'url': 'php/crudComment.php',
'type': 'POST',
'data': {
'invitId': $.urlParam('invitId')
}},
table: '#comment',
fields: [
{
"label": "date:",
"name": "date",
"type": "datetime",
"format": "YYYY-MM-DD HH:mm:ss"
},
{
"label": "user:",
"name": "user"
},
{
"label": "comment:",
"name": "comment"
}
]
});
Here is part of my script "crudComment.php" which handles edits. Here is am looping through $_POST to see what I am being passed, and printing to the console.
foreach ($_POST as $param_name => $param_val) {
fb($param_name);
fb("=");
fb($param_val);
fb("---------------");
}
When I click on an entry in the table, click EDIT and then UPDATE, I get nested data passed via POST to my script. I can extract nearly everything, but I need to get the ID of the record that was being edited. This is sent as "row_3" where 3 is the ID I need. Here is what is printed to my console from the above php:
data
=
{row_3: {…}}row_3:
comment: "some comment"
date: "2020-11-12 17:38:56"
user: "some user"
__proto__: Object__proto__: Object
---------------
action
=
edit
---------------
invitId
=
21212
---------------
The part that is perplexing me is how to extract "row_3" in this case, so I can derive the row id of the record being edited. I can't figure out how to refer to this in php! Or, maybe another way to pass the record id.
Replies
I resolved my problem by adding a hidden column containing the commentId, and then this gets passed to my script.
Resolved-
Actually, I do have a remaining issue. I have hidden my commentId column in the table, but how can I hide the field in the edit window?
That's an easy one. If you never want to see it on the Editor form, just remove it from the list of fields on the Editor initialisation. If you want it temporarily removed, call
hide()
orfield().hide()
,Colin
Colin- thanks for the idea. I can't simply remove the field from the editor initialization- I need to pass the value to my script. I need the field to exist, but just be invisible.
I set up a listener for the preOpen event and hide I the field. The value gets passed now, and I don't see the field. Yay!
I added this to the end of my editor config: