Hi,
I have a custom file that’s opened by a button on the list page, which updates two values in my database using a REST API.
Lavori->Row_Rendered:
<button type="button" class="btn-default btn dropdown-toggle btn-custom" data-title="Modifica" data-bs-toggle="dropdown" data-bs-auto-close="true"><i data-phrase="ButtonListOptions" class="fa-solid fa-edit ew-icon"><span class="visually-hidden">Modifica</span></i></button><ul class="dropdown-menu ew-dropdown-menu ew-list-options btn-custom">
<li><a class="ew-row-link ew-edit dropdown-item" data-ew-action="modal" data-ajax="true" data-url="editlavori?x_id='. $this->id->CurrentValue .'" href="#"><i class="fa-solid fa-pen ew-icon me-2"><span class="visually-hidden">Lavori</span></i>Lavori</a></li>
</ul>
</div>';
Custom FIle->editlavori.php ->Include Common File → YES
Custom File → editlavori.php → Custom Template → Content:
<label for="note">Note:</label>
<textarea name="note" id="note"></textarea><br />
<br>
<label for="urgente">Urgente?</label>
<input type="radio" id="si" name="urgente" value="1">
<label for="si">Si</label>
<input type="radio" id="no" name="urgente" value="0">
<label for="no">No</label><br />
<br>
<button type="button" class="btn btn-primary ew-btn" id="btn-id" data-bs-dismiss="modal">Invia Dati</button>
<button type="button" class="btn btn-default ew-btn" data-bs-dismiss="modal">Chiudi</button>
<?php
$id = isset($_GET['x_id']) ? $_GET['x_id'] : 0;
?>
<script>
$(document).ready(function() {
$('.modal-footer').hide();
loadExistingData();
$('#btn-id').click(function(event) {
sendCurlRequest();
});
});
function loadExistingData() {
var key = <?php echo json_encode($id); ?>;
var object = "lavori";
$.ajax({
url: ew.getApiUrl(["view", object, key]),
type: "GET",
success: function(data) {
console.log("Dati ricevuti:", data);
$("#note").val(data.lavori.note || '');
$("input[name='urgente'][value='" + data.lavori.urgente + "']").prop('checked', true);
},
error: function(error) {
console.error("Errore nel caricamento dei dati esistenti: " + JSON.stringify(error));
}
});
}
function sendCurlRequest() {
var note = $("#note").val();
var urgente = $("input[name='urgente']:checked").val();
var object = "lavori";
var key = <?php echo json_encode($id); ?>;
$.ajax({
url: ew.getApiUrl(["edit", object, key]),
type: "POST",
data: {
"note": note,
"urgente": urgente
},
success: function (data) {
console.log("Richiesta riuscita: " + data);
window.location.reload();
},
error: function (error) {
console.error("Errore: " + JSON.stringify(error));
window.location.reload();
}
});
}
</script>
In version 2024, it was working perfectly, updating only the two values as intended. However, in version 2025, it sets every column to NULL except for the two columns that the script is supposed to update, which receive the correct values.
Do you have any idea why this might be happening?
Now, as a test, I’m trying to do the same thing with Doctrine ORM, but I’m stuck on this as well.
<?php
$em = EntityManager();
$id = isset($_GET['x_id']) ? $_GET['x_id'] : 0;
$note = '';
$urgente = null;
$lavoro = $em->find(Entity\Lavori::class, $id);
if ($lavoro) {
$note = $lavoro->getNote();
$urgente = $lavoro->getUrgente();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$note = $_POST['note'];
$urgente = $_POST['urgente'];
if ($lavoro) {
$lavoro->setNote($note);
$lavoro->setUrgente($urgente);
$em->persist($lavoro);
$em->flush();
echo "<script>alert('Dati aggiornati con successo!'); window.location.href = 'your_redirect_url.php';</script>";
}
}
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gestione Lavori</title>
</head>
<body>
<form method="POST" action="">
<label for="note">Note:</label>
<input type="hidden" name="<?= $TokenNameKey ?>" value="<?= $TokenName ?>">
<input type="hidden" name="<?= $TokenValueKey ?>" value="<?= $TokenValue ?>">
<textarea name="note" id="note"><?php echo htmlspecialchars($note); ?></textarea><br />
<br>
<label for="urgente">Urgente?</label>
<input type="radio" id="si" name="urgente" value="1" <?php if ($urgente == 1) echo 'checked'; ?>>
<label for="si">Si</label>
<input type="radio" id="no" name="urgente" value="0" <?php if ($urgente == 0) echo 'checked'; ?>>
<label for="no">No</label><br />
<br>
<button type="submit" class="btn btn-primary ew-btn">Invia Dati</button>
<button type="button" class="btn btn-default ew-btn" onclick="window.history.back()">Chiudi</button>
</form>
</body>
</html>
The connection, the GET request, and the population of my HTML work correctly, but the POST request is not functioning. It closes the editlavori.php window, sets a filter in the lavori list, and doesn’t update any values.