diff --git a/app/assets/js/custom.js b/app/assets/js/custom.js index d3dfd7a..c13bb34 100644 --- a/app/assets/js/custom.js +++ b/app/assets/js/custom.js @@ -199,8 +199,21 @@ function ajax_request(options) { } options.data = { json: JSON.stringify(payloadJson) }; + + // IF formData exist, we pass as $_POST [not json] + if (options.formData instanceof FormData) { + // THE BYPASS: If formData exists, move all text data into it + Object.entries(payloadJson).forEach(([key, value]) => { + options.formData.append(key, value); + }); + // Override options.data with the full FormData object + options.data = options.formData; + } } + // --- START MODIFIED $.AJAX BLOCK --- + let isSendingFiles = (options.data instanceof FormData); + if (options.debugMode) { console.log("REQUEST DATA:", options.data); } @@ -219,7 +232,10 @@ function ajax_request(options) { type: options.type || "POST", url: options.url, data: options.data, - dataType: "json" + dataType: "json", + // These two settings are only triggered when sending files + processData: isSendingFiles ? false : true, + contentType: isSendingFiles ? false : "application/x-www-form-urlencoded; charset=UTF-8" }) .then(function (res) { diff --git a/app/assets/utils/db_auth.php b/app/assets/utils/db_auth.php index eb0fb84..87ba99f 100644 --- a/app/assets/utils/db_auth.php +++ b/app/assets/utils/db_auth.php @@ -58,14 +58,19 @@ if(!empty($_SESSION["login_company_id"])){ // set up ANSWER $answer = array("success"=>0, "message"=>""); -if(!isset($_POST['json'])) -{ - $answer["message"] = "No data receive!"; +if (isset($_POST['json'])) { +// Old Method: Data is wrapped in a JSON string +$data = json_decode($_POST['json'], true); +} else if (isset($_POST['otp'])) { + // New Method: Data is sent directly (FormData) + // We check for 'otp' because every request should have one + $data = $_POST; +} else { + // Truly no data received + $answer["message"] = "Request denied: No valid JSON payload or Form Data detected."; exit(json_encode($answer)); } -$data = json_decode($_POST['json'],true); - // incase logging in if(!empty($_SESSION["login_company_id"])){ diff --git a/app/contact/api/engine/manage_contact.php b/app/contact/api/engine/manage_contact.php index e69de29..096b6fd 100644 --- a/app/contact/api/engine/manage_contact.php +++ b/app/contact/api/engine/manage_contact.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/app/contact/manage_contact.php b/app/contact/manage_contact.php index 4db8455..d8bb314 100644 --- a/app/contact/manage_contact.php +++ b/app/contact/manage_contact.php @@ -104,7 +104,7 @@