-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_handle.js
36 lines (29 loc) · 898 Bytes
/
form_handle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function generate_tracking_code(){
const char = "Aa1Bb2Cc3Dd4Ee5Ff6Gg7Hh8Ii9Jj10Kk11Ll12Mm13Nn14Oo15Pp16Qq17Rr18Ss19Tt20Uu21Vv22Ww23Xx24Yy25Zz26";
let output="";
for(i=1;i<=4;i++){
var random = char.charAt(Math.floor(Math.random() * char.length));
output += random;
}
document.getElementById("tracking_code").value = output;
return code;
}
let form = document.querySelector("form");
form.addEventListener("submit",(e)=>{
e.preventDefault();
let tracking_code = generate_tracking_code();
const formData = new FormData(form);
// Create a new fetch request
fetch('/form_handle.php', {
method: 'POST',
body: formData,
})
.then(response => {
// Handle the response
document.write(`/collect.php?code=${tracking_code} \n \n /retrieve.php?code=${tracking_code}`);
})
.catch(error => {
// Handle errors
document.write(error);
});
})