-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmail.js
46 lines (34 loc) · 1.05 KB
/
mail.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
const firebaseConfig = {
// copy your firebase config informations
};
// initialize firebase
firebase.initializeApp(firebaseConfig);
// reference your database
var contactFormDB = firebase.database().ref("contactForm");
document.getElementById("contactForm").addEventListener("submit", submitForm);
function submitForm(e) {
e.preventDefault();
var name = getElementVal("name");
var emailid = getElementVal("emailid");
var msgContent = getElementVal("msgContent");
saveMessages(name, emailid, msgContent);
// enable alert
document.querySelector(".alert").style.display = "block";
// remove the alert
setTimeout(() => {
document.querySelector(".alert").style.display = "none";
}, 3000);
// reset the form
document.getElementById("contactForm").reset();
}
const saveMessages = (name, emailid, msgContent) => {
var newContactForm = contactFormDB.push();
newContactForm.set({
name: name,
emailid: emailid,
msgContent: msgContent,
});
};
const getElementVal = (id) => {
return document.getElementById(id).value;
};