-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (46 loc) · 1.49 KB
/
index.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
const firebaseConfig = {
apiKey: "AIzaSyBAf0skD-8rZ4Nuv0EUiRTR3ITt5jtc8qI",
authDomain: "sparkz-2023.firebaseapp.com",
databaseURL: "https://sparkz-2023-default-rtdb.firebaseio.com",
projectId: "sparkz-2023",
storageBucket: "sparkz-2023.appspot.com",
messagingSenderId: "422188327792",
appId: "1:422188327792:web:058e37ca07460d15e8a5b5",
measurementId: "G-EYRVF47YWE"
};
// 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 email = getElementVal("email");
var food = getElementVal("food");
var size = getElementVal("size");
var roll = getElementVal("roll");
saveMessages(name, email, food, size, roll);
// enable alert
// document.querySelector(".alert").style.display = "block";
// remove the alert
// setTimeout(() => {
// document.querySelector(".alert").style.display = "none";
// }, 3000);
// reset the form
window.location.href = "thanks.html";
document.getElementById("contactForm").reset();
}
const saveMessages = (name, email, food, size, roll) => {
var newContactForm = contactFormDB.push();
newContactForm.set({
name: name,
email: email,
food: food,
size: size,
roll: roll,
});
};
const getElementVal = (id) => {
return document.getElementById(id).value;
};