forked from Anuragjais189/webathon3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.js
55 lines (44 loc) · 1.74 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
47
48
49
50
51
52
53
54
55
const firebaseConfig = {
apiKey: "AIzaSyBBKQvm_xI76jzVFcJJHteGmlsIIlw2Q8g",
authDomain: "webathon-c9c37.firebaseapp.com",
databaseURL: "https://webathon-c9c37-default-rtdb.firebaseio.com",
projectId: "webathon-c9c37",
storageBucket: "webathon-c9c37.appspot.com",
messagingSenderId: "448603157508",
appId: "1:448603157508:web:ae0983bc922963bd37b151"
};
// 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 firstName = getElementVal("firstName");
var lastName = getElementVal("lastName");
var email = getElementVal("email");
var residentialAddress = getElementVal("residentialAddress");
var experience = getElementVal("experience");
saveMessages(firstName ,lastName, email, residentialAddress , experience);
// 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 = (firstName ,lastName, email, residentialAddress , experience) => {
var newContactForm = contactFormDB.push();
newContactForm.set({
firstName: firstName,
lastName: lastName,
email: email,
residentialAddress:residentialAddress,
experience:experience,
});
};
const getElementVal = (id) => {
return document.getElementById(id).value;
};