-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalval.js
46 lines (40 loc) · 1.44 KB
/
valval.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
36
37
38
39
40
41
42
43
44
45
46
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function () {
'use strict'
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.querySelectorAll('.needs-validation')
// Loop over them and prevent submission
Array.prototype.slice.call(forms)
.forEach(function (form) {
var myModal = new bootstrap.Modal(document.getElementById('successmodal'))
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
if (form.checkValidity()) {
//show
myModal.show();
event.preventDefault()
event.stopPropagation()
//take data
const formData = new FormData(form);
//Send to php with fetch
fetch("receive.php", {
method: "post",
body: formData
}).then(function (response) {
return response.text;
}).then(function (text) {
//console.log(text);
}).catch(function (error) {
console.log(error);
})
//reset form
form.classList.remove('was-validated')
form.reset()
}
}, false)
})
})()