jsgrid-php
jsgrid-php copied to clipboard
Editing custom fields (with images and download-links) does not work
Hello,
I used your jsfiddle.net/tabalinas/ccy9u7pa/16/ example and several other threads to add upload-fields for an image (that is shown in a cell) and a pdf-file (thats offered via download-link in a cell). Showing and Inserting works fine, but I have some trouble with the Editing mode, because I want those files to be overwritten, if the user uploads another file. Let me show what I´ve done so far:
This is my controller:
updateItem: function (items) {
var formData = new FormData();
formData.append("punch_status", items.punch_status);
formData.append("punch_place", items.punch_place);
formData.append("punch_product", items.punch_product);
formData.append("punch_type", items.punch_type);
formData.append("punch_run", items.punch_run);
formData.append("punch_generation", items.punch_generation);
formData.append("punch_date", items.punch_date);
formData.append("punch_customers", items.punch_customers);
formData.append("punch_orders", items.punch_orders);
formData.append("punch_description", items.punch_description);
formData.append("punch_note", items.punch_note);
formData.append("punch_pdfbig", items.punch_pdfbig);
formData.append("punch_pdfsmall", items.punch_pdfsmall);
formData.append("punch_image", items.punch_image);
return $.ajax({
method: "put",
type: "PUT",
url: "/punches/",
data: formData,
contentType: false,
processData: false,
success: function () {
$("#jsGrid").jsGrid("loadData");
}
});
},
}```
This is my cell config:
```{
title: "Bild",
name: "punch_image",
itemTemplate: function(val) {
return $("<a data-toggle='lightbox'>").attr("href", "apps/stanzen/img/" + val).html($("<img class='img-fluid'>").attr("src", "apps/stanzen/img/" + val).css({ width: 80 }));
},
insertTemplate: function() {
var insertControl = this.insertControl = $("<input>").prop("type", "file");
return insertControl;
},
insertValue: function() {
return this.insertControl[0].files[0];
},
editTemplate: function() {
var editControl = this.editControl = $("<input>").prop("type", "file");
return editControl;
},
editValue: function() {
return this.editControl[0].files[0];
},
align: "center",
width: 120,
editing: true,
inserting: true,
filtering: false
},{
title: "Bogen",
name: "punch_pdfbig",
itemTemplate: function(val) {
if (val != '') {
return $("<a>").attr("href", "apps/stanzen/pdfbig/" + val).text('Bogen');
}
},
insertTemplate: function() {
var insertControl = this.insertControl = $("<input>").prop("type", "file");
return insertControl;
},
insertValue: function() {
return this.insertControl[0].files[0];
},
editTemplate: function() {
var editControl = this.editControl = $("<input>").prop("type", "file");
return editControl;
},
editValue: function() {
return this.editControl[0].files[0];
},
align: "center",
width: 120,
editing: true,
inserting: true,
filtering: false
},
{
title: "Einzelnutzen",
name: "punch_pdfsmall",
itemTemplate: function(val) {
if (val != '') {
return $("<a>").attr("href", "apps/stanzen/pdfbig/" + val).text('Einzelnutzen');
}
},
insertTemplate: function() {
var insertControl = this.insertControl = $("<input>").prop("type", "file");
return insertControl;
},
insertValue: function() {
return this.insertControl[0].files[0];
},
editTemplate: function() {
var editControl = this.editControl = $("<input>").prop("type", "file");
return editControl;
},
editValue: function() {
return this.editControl[0].files[0];
},
align: "center",
width: 120,
editing: true,
inserting: true,
filtering: false
}```
At least my AJAX-Call for PUT:
```case "PUT":
parse_str(file_get_contents("php://input"), $_PUT);
$result = $punches->update(array(
"punch_id" => $_PUT["punch_id"],
"punch_status" => intval($_PUT["punch_status"]),
"punch_place" => intval($_PUT["punch_place"]),
"punch_product" => $_PUT["punch_product"],
"punch_type" => intval($_PUT["punch_type"]),
"punch_run" => $_PUT["punch_run"],
"punch_generation" => $_PUT["punch_generation"],
"punch_date" => $_PUT["punch_date"],
"punch_customers" => $_PUT["punch_customers"],
"punch_orders" => $_PUT["punch_orders"],
"punch_description" => $_PUT["punch_description"],
"punch_note" => $_PUT["punch_note"],
"punch_pdfbig" => $_PUT["punch_pdfbig"],
"punch_pdfsmall" => $_PUT["punch_pdfsmall"],
"punch_image" => $_PUT["punch_image"]
));
break;```
When I want to process the given array, I always get an empty array in $data and $_FILES, means the following var_dump in the Repository is always empty:
```public function update($data)
{
var_dump($data);
var_dump($_FILES);
exit();
$sql = "UPDATE punches SET punch_status = :punch_status, punch_place = :punch_place, punch_product = :punch_product, punch_type = :punch_type, punch_run = :punch_run, punch_generation = :punch_generation, punch_date = :punch_date, punch_customers = :punch_customers, punch_orders = :punch_orders, punch_description = :punch_description, punch_note = :punch_note WHERE punch_id = :punch_id";
$q = $this->db->prepare($sql);
$q->bindParam(":punch_id", $data['punch_id'], PDO::PARAM_INT);
$q->bindParam(":punch_status", $data['punch_status'], PDO::PARAM_INT);
$q->bindParam(":punch_place", $data['punch_place'], PDO::PARAM_INT);
$q->bindParam(":punch_product", $data['punch_product'], PDO::PARAM_STR);
$q->bindParam(":punch_type", $data['punch_type'], PDO::PARAM_INT);
$q->bindParam(":punch_run", $data['punch_run'], PDO::PARAM_INT);
$q->bindParam(":punch_generation", $data['punch_generation'], PDO::PARAM_INT);
$q->bindParam(":punch_date", $data['punch_date'], PDO::PARAM_INT);
$q->bindParam(":punch_customers", $data['punch_customers'], PDO::PARAM_STR);
$q->bindParam(":punch_orders", $data['punch_orders'], PDO::PARAM_STR);
$q->bindParam(":punch_description", $data['punch_description'], PDO::PARAM_STR);
$q->bindParam(":punch_note", $data['punch_note'], PDO::PARAM_STR);
/*$q->bindParam(":punch_pdfbig", $_FILES['punch_pdfbig']['name'], PDO::PARAM_STR);
$q->bindParam(":punch_pdfsmall", $_FILES['punch_pdfsmall']['name'], PDO::PARAM_STR);
$q->bindParam(":punch_image", $_FILES['punch_image']['name'], PDO::PARAM_STR);*/
$q->execute();
}```
Can you please give me a hint how to solve this.
Regards, Dominik