Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck which form fields were updated in PHP/jQuery
    primarykey
    data
    text
    <p>I have a form with ~20 fields to update a record. When a user submits the form, I would like to log which fields were updated (changed) in my <code>update_log</code> table along with the updated value, the username, and time. (Ex: "Andrew updated 'Supplier' to 'Acme Inc.' on November 22nd at 3:00 pm)</p> <p>Previously, I've had success in instances where a single field auto-saves because as soon as the single field updates I can log it. But with a form with 20 fields, this is more difficult because I'm updating the entire form at once and do not want to log fields which didn't change.</p> <p>Here's the Javascript I'm using to <code>POST</code> the update to a PHP file, which runs an update query using the <code>$_POST</code> data:</p> <pre><code>$("body").on('click', "#update-shipment-button", function(e){ e.preventDefault(); var shipment_id= $("#update-shipment-button").attr('data-shipment-id'); var clientName = $("#form-client-name").val(); var poNumber = $("#form-po-number").val(); var shipmentStatus = $("#form-shipment-status").val(); var supplier = $("#form-supplier").val(); var shipper = $("#form-shipper").val(); var departureDate = $("#form-departure-date").val(); var arrivalDate = $("#form-arrival-date").val(); var freightForwarder = $("#form-freight-forwarder").val(); var shippingMethod = $("#form-shipping-method").val(); var originCountry = $("#form-origin-country").val(); var data = { shipment_id: shipment_id, clientName: clientName, poNumber: poNumber, shipmentStatus: shipmentStatus, supplier: supplier, shipper: shipper, departureDate: departureDate, arrivalDate: arrivalDate, freightForwarder: freightForwarder, shippingMethod: shippingMethod, originCountry: originCountry, } // Deliver the payload! $.ajax({ type: "POST", url: "st_update_shipment_query.php", dataType:"JSON", data: data, success:function(response){ console.log("Successfully updated."); }, error:function (xhr, ajaxOptions, thrownError){ console.log(xhr.status); console.log(ajaxOptions); console.log(thrownError); } }); }); </code></pre> <p>What is the best way to approach this? Any help is appreciated :) I can clarify the question if needed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload