I am using form and dropzone library to upload document and I was doing testing whether my document ID is capturing or not. Its not capturing and when I check and see the issue is my form dropzone library is preventing it and I am not sure why. I will appreciate any help to identify the issue
This is my code
var tblCandidateDocumentList = $('#tblCandidateDocumentList').DataTable({
ajax: {
"url": "action/fn_espdb_getData.php?mod=candidateDocumentList",
"dataSrc": "candidateDocumentList"
},
columns: [
{ data: null },
{data: null},
{ data: 'document_type_name' },
{
data: null,
render: function (data, type, row) {
return `
<div class="col-12">
<div class="card">
<div class="card-body">
<form action="/upload" class="dropzone dropZoneCandidate needsclick" data-doc-id="${row.document_id}" id="dropzone-multi-${row.document_id}">
<input type="hidden" id="documentTypeID" name="documentTypeID" value="${row.document_id}" class="form-control" readonly>
<div class="dz-message needsclick">
Drop files here or click to upload
</div>
<div class="fallback">
<input id="file_${row.document_id}" name="file_${row.document_id}" type="file" multiple/>
</div>
</form>
</div>
</div>
</div>
`;
}
},
],
columnDefs: [
{
// For Checkboxes
targets: 0,
searchable: false,
orderable: false,
render: function () {
return '<input type="checkbox" class="dt-checkboxes form-check-input">';
},
checkboxes: {
selectRow: true,
selectAllRender: '<input type="checkbox" class="form-check-input">'
}
},
],
order: [[1, 'desc']],
dom: '<"row"<"col-sm-12 col-md-6"l><"col-sm-12 col-md-6 d-flex justify-content-center justify-content-md-end mt-n6 mt-md-0"f>><"table-responsive"t><"row"<"col-sm-12 col-md-6"i><"col-sm-12 col-md-6"p>>',
language: {
paginate: {
next: '<i class="bx bx-chevron-right bx-18px"></i>',
previous: '<i class="bx bx-chevron-left bx-18px"></i>'
}
},
select: {
style: 'multi'
}
});
This is my backend code
case “addCandidateDetails”:
// Collect form data
$candidateID = $_POST['candidateID'] > 0 ? $_POST['candidateID'] : NULL;
$candidateName = $_POST['candidateName'] == "" ? NULL : $_POST['candidateName'];
$candidateNationality = $_POST['candidateNationality'] == "" ? NULL : $_POST['candidateNationality'];
$candidateGender = $_POST['candidateGender'] == "" ? NULL : $_POST['candidateGender'];
$candidateMaritalStatus = $_POST['candidateMaritalStatus'] == "" ? NULL : $_POST['candidateMaritalStatus'];
$candidateDOB = $_POST['candidateDOB'] == "" ? NULL : $_POST['candidateDOB'];
$candidateAge = $_POST['candidateAge'] == "" ? NULL : $_POST['candidateAge'];
$candidateEmail = $_POST['candidateEmail'] == "" ? NULL : $_POST['candidateEmail'];
$candidateCompany = $_POST['candidateCompany'] == "" ? NULL : $_POST['candidateCompany'];
$candidatePassportNo = $_POST['candidatePassportNo'] == "" ? NULL : $_POST['candidatePassportNo'];
$candidatePassportIssueDate = $_POST['candidatePassportIssueDate'] == "" ? NULL : $_POST['candidatePassportIssueDate'];
$candidatePassportExpiryDate = $_POST['candidatePassportExpiryDate'] == "" ? NULL : $_POST['candidatePassportExpiryDate'];
$candidatePlaceOfIssue = $_POST['candidatePlaceOfIssue'] == "" ? NULL : $_POST['candidatePlaceOfIssue'];
$inMalaysia = $_POST['inMalaysia'] == "" ? NULL : $_POST['inMalaysia'];
$visaCollectionCenter = $_POST['visaCollectionCenter'] == "" ? NULL : $_POST['visaCollectionCenter'];
$candidatePermitType = $_POST['candidatePermitType'] == "" ? NULL : $_POST['candidatePermitType'];
// Additional data for tbl_candidate_documents
$documentTypeID = $_POST['documentTypeID'] == "" ? NULL : $_POST['documentTypeID'];
// File upload handling
$uploadDirectory = '/uploads/candidate_files/';
$uploadedFilePath = NULL;
echo "Candidate Name : " . $candidateName . "<br>";
echo "candidate Nationality : " . $candidateNationality . "<br>";
echo "Candidate Permit Type : " . $candidatePermitType . "<br>";
echo "Candidate Document ID : " . $documentTypeID . "<br>";
exit();
if (isset($_FILES['candidateFile']) && $_FILES['candidateFile']['error'] == UPLOAD_ERR_OK) {
$fileTmpPath = $_FILES['candidateFile']['tmp_name'];
$fileName = $_FILES['candidateFile']['name'];
$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
// Sanitize candidate name and passport number for the filename
$sanitizedCandidateName = preg_replace("/[^a-zA-Z0-9]/", "_", $candidateName);
$sanitizedPassportNo = preg_replace("/[^a-zA-Z0-9]/", "_", $candidatePassportNo);
// Construct the new file name
$newFileName = "{$sanitizedCandidateName}_{$sanitizedPassportNo}_Document.{$fileExtension}";
$uploadedFilePath = $uploadDirectory . $newFileName;
// Move file to the destination
if (move_uploaded_file($fileTmpPath, $_SERVER['DOCUMENT_ROOT'] . $uploadedFilePath)) {
// Insert file details into tbl_candidate_documents
DB::insert('tbl_candidate_documents', [
'candidate_id' => $candidateID,
'document_type_id' => $documentTypeID,
'permit_id' => $candidatePermitType,
'document_name' => $newFileName,
'document_path' => $uploadedFilePath,
'status' => 1,
'entry_user' => $username,
'entry_date' => DB::sqlEval('NOW()')
]);
} else {
die('Error uploading file.');
}
}
// Insert candidate details into tbl_candidate
DB::insert('tbl_candidate', [
'candidate_id' => $candidateID,
'candidate_name' => $candidateName,
'candidate_nationality' => $candidateNationality,
'candidate_gender' => $candidateGender,
'candidate_dob' => $candidateDOB,
'candidate_age' => $candidateAge,
'candidate_email' => $candidateEmail,
'candidate_customer' => $candidateCompany,
'candidate_passport_no' => $candidatePassportNo,
'passport_issue_date' => $candidatePassportIssueDate,
'passport_expiry_date' => $candidatePassportExpiryDate,
'candidate_issue_place' => $candidatePlaceOfIssue,
'candidate_is_in_malaysia' => $inMalaysia,
'candidate_visa_collection_center' => $visaCollectionCenter,
'candidate_permit_type_id' => $candidatePermitType,
'status' => 1,
'entry_user' => $username,
'entry_date' => DB::sqlEval('NOW()')
]);
break;