-
Notifications
You must be signed in to change notification settings - Fork 0
/
projectB.js
33 lines (33 loc) · 1.16 KB
/
projectB.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
document.querySelector("#validation_form").addEventListener("submit", (e) => {
e.preventDefault();
let form = document.querySelector("#registration_form");
const data = new URLSearchParams();
for (const p of new FormData(form)) {
data.append(p[0], p[1]);
}
console.log(data);
fetch("http://localhost/step2/projectB.php", {
method: "POST",
body: data,
})
.then((response) => response.json())
.then((response) => {
console.log(response);
if (response.result == true) {
console.log(response.redirect);
window.location.replace(response.redirect);
} else {
document.querySelector(".nameError").innerHTML =
response.message["nameError"];
document.querySelector(".surnameError").innerHTML =
response.message["surnameError"];
document.querySelector(".phoneError").innerHTML =
response.message["phoneError"];
document.querySelector(".mailError").innerHTML =
response.message["emailError"];
document.querySelector(".dateError").innerHTML =
response.message["dateError"];
}
})
.catch((error) => console.log("Error"));
});