-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.js
99 lines (69 loc) · 2.94 KB
/
contact.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const contactForm = document.getElementById('contact-form');
const fromEmail = document.getElementById('fromEmail');
const fromName = document.getElementById('from_name');
const subject = document.getElementById('subject');
const message = document.getElementById('message');
const errorElement = document.getElementById('error');
submitButton.addEventListener('click', function(event) {
event.preventDefault();
let messages = [];
if (fromEmail.value === '' | fromEmail.value == null) {
messages.push('Email is verplicht!');
}
if (fromName.value === '' | fromName.value == null) {
messages.push('Naam is verplicht!');
}
if (subject.value === '' | subject.value == null) {
messages.push('Onderwerp is verplicht!');
}
if (message.value === '' | message.value == null) {
messages.push('Boodschap is verplicht!');
}
if (messages.length > 0) {
errorElement.innerHTML = messages.join('\n <br> <br>');
errorElement.style.display = "flex";
errorElement.style.width = "50vw";
errorElement.classList.add('container');
errorElement.style.justifyContent = "center";
errorElement.style.backgroundColor = "rgb(216, 62, 62)";
errorElement.style.margin = "10px auto";
errorElement.style.color = "#fff";
errorElement.style.fontWeight = "bold";
errorElement.style.fontFamily = "Roboto";
errorElement.style.border = "1px solid rgb(216, 62, 62)";
errorElement.style.padding = "10px";
errorElement.style.borderRadius = "20px";
} else {
let Params = {
from_email: fromEmail.value,
reply_to: fromEmail.value,
from_name: fromName.value,
subject: subject.value,
to_name: 'Emma Muroni',
message: message.value
};
emailjs.send('service_0c1qqng', 'template_jefydrp', Params)
.then(res => console.log("Bericht verzonden!"))
.catch(err => console.log(err))
setTimeout(function() {
for (i = 0; i < inputs.length; i++) {
inputs[i].value = "";
}
message.value = "";
contactForm.style.opacity = "0";
errorElement.innerHTML = "Bericht verzonden!";
errorElement.style.display = "flex";
errorElement.style.width = "50vw";
errorElement.classList.add('container');
errorElement.style.justifyContent = "center";
errorElement.style.backgroundColor = "rgb(41, 175, 59)";
errorElement.style.margin = "10px auto";
errorElement.style.color = "#fff";
errorElement.style.fontWeight = "bold";
errorElement.style.fontFamily = "Roboto";
errorElement.style.border = "1px solid rgb(41, 175, 59)";
errorElement.style.padding = "10px";
errorElement.style.borderRadius = "20px";
}, 3000);
}
})