Skip to content

Commit fd9bd55

Browse files
authored
Add files via upload
1 parent e6de9a9 commit fd9bd55

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

html/form.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ <h5 class="card-title">B. MAKLUMAT BAPA / PENJAGA</h5>
116116
<h5 class="card-title">C. Muat Naik Dokumen</h5>
117117
<div class="form-label">
118118
<label for="childSchool">Gambar Berukuran Passport</label>
119-
<input type="file" class="form-control" aria-label="Image file upload" accept="image/png" required>
119+
<input type="file" class="form-control" aria-label="Image file upload" accept="image/png" id="studImg" required>
120120
<div class="valid-feedback">Diterima</div><div class="invalid-feedback">Tidak Diterima</div><div class="error"></div>
121121
</div>
122122
<div class="form-label">
123123
<label for="childSchool">Transcript Terkini</label>
124-
<input type="file" class="form-control" aria-label="PDF file upload" accept="application/pdf" required>
124+
<input type="file" class="form-control" aria-label="PDF file upload" accept="application/pdf" id="studTranscript" required>
125125
<div class="valid-feedback">Diterima</div><div class="invalid-feedback">Tidak Diterima</div><div class="error"></div>
126126
</div>
127127
</div>

html/result.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="row">
1818
<div class="col-md-8">
1919
<div class="logo-uitm">
20-
<img src="../asstes/uitm-only.jpg" alt="" class="uitm">
20+
<img src="" alt="" class="uitm" id="studImg">
2121
<h4>PEJABAT BENDAHARI</h4>
2222
<h5>PERMOHONAN SKIM KHIDMAT PELAJAR</h5>
2323
<p class="sila"><b>(Sila lampirkan salinan nombor kad pengenalan</b></p>
@@ -29,7 +29,7 @@ <h5>PERMOHONAN SKIM KHIDMAT PELAJAR</h5>
2929
<p>PK.PBUiTM.PPK.(O).08/01</p>
3030
</div>
3131
<div class="gambar-pemohon">
32-
<img src="../assets/dev.jpeg" alt="" class="result-img"> <!-- user upload hamba, save as SKP.jpeg -->
32+
<img src="" alt="" class="result-img" id="displayImage"> <!-- user upload hamba, save as SKP.jpeg -->
3333
</div>
3434
</div>
3535
</div>

js/form.js

+38-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const mJob = document.getElementById('mJob');
1313
const mIncome = document.getElementById('mIncome');
1414
const childSchool = document.getElementById('childSchool');
1515
const childWork = document.getElementById('childWork');
16+
const studTrans = document.getElementById('studTranscript');
17+
const studImg = document.getElementById('studImg');
1618

1719

1820
forms.addEventListener('submit', e => {
@@ -58,6 +60,8 @@ const validateInputs = () => {
5860
const mIncomeValue = mIncome.value.trim();
5961
const childSchoolValue = childSchool.value.trim();
6062
const childWorkValue = childWork.value.trim();
63+
const studImgValue = studImg.value;
64+
const studTransValue = studTrans.value;
6165

6266

6367
if (studNameValue === '') {
@@ -166,10 +170,24 @@ const validateInputs = () => {
166170
counter++;
167171
}
168172

173+
if (studImgValue === '') {
174+
setError(studImg, "Sila muat naik gambar.");
175+
} else {
176+
setSuccess(studImg);
177+
counter++;
178+
}
179+
180+
if (studTransValue === '') {
181+
setError(studTrans, "Sila muat naik transkrip.");
182+
} else {
183+
setSuccess(studTrans);
184+
counter++;
185+
}
186+
169187
console.log(counter)
170188

171-
if (counter === 15) {
172-
window.location.href = "result.html";
189+
if (counter === 17) {
190+
// window.location.href = "result.html";
173191

174192
localStorage.setItem('studName', studNameValue);
175193
localStorage.setItem('studBirth', studBirthValue);
@@ -187,6 +205,24 @@ const validateInputs = () => {
187205
localStorage.setItem('childSchool', childSchoolValue);
188206
localStorage.setItem('childWork', childWorkValue);
189207

208+
const file = studImg.files[0];
209+
210+
211+
if (file) {
212+
const reader = new FileReader();
213+
214+
reader.onload = function(event) {
215+
const base64String = event.target.result;
216+
217+
// Store the Base64 string in local storage
218+
localStorage.setItem('uploadedImage', base64String);
219+
};
220+
221+
reader.readAsDataURL(file);
222+
} else {
223+
alert("No image uploaded.")
224+
}
225+
190226
window.location.href = "result.html";
191227

192228
} else {

js/result.js

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ const p_values = [
3838

3939
const blankElements = document.querySelectorAll('.blank');
4040

41+
const uploadedImage = document.getElementById('uploadedImage');
42+
43+
const base64String = localStorage.getItem('uploadedImage');
44+
45+
const displayImage = document.getElementById('displayImage');
46+
47+
console.log(base64String)
48+
49+
if (base64String) {
50+
displayImage.src = base64String;
51+
} else {
52+
// Handle the case when the Base64 string is not available
53+
displayImage.alt = "No image found";
54+
}
55+
4156
localStorageKeys.forEach((key, index) => {
4257
const value = localStorage.getItem(key);
4358

0 commit comments

Comments
 (0)