-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
53 lines (43 loc) · 1.41 KB
/
db.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
const firebaseConfig = {
apiKey: "AIzaSyCHbJeBDBqRYgoBFL4oMJW86z8KAmgyG4Y",
authDomain: "uniment-5d053.firebaseapp.com",
databaseURL: "https://uniment-5d053-default-rtdb.firebaseio.com",
projectId: "uniment-5d053",
storageBucket: "uniment-5d053.appspot.com",
messagingSenderId: "411317673097",
appId: "1:411317673097:web:c993f8e11bfd01fef83a58"
};
// initialization
firebase.initializeApp(firebaseConfig);
// reference
const ContactFormDB = firebase.database().ref('ContactForm');
document.getElementById("contact_form").addEventListener("submit", submitForm);
function submitForm(e){
e.preventDefault();
var Uname = getElementVal('Uname');
var email = getElementVal('email');
var mobile = getElementVal('mobile');
var message = getElementVal('msg');
// console.log(Uname, email, mobile, message);
saveMsg(Uname, email, mobile, message);
// enable alert
document.querySelector( ".alert" ).style.display = "block";
// close the alert after 3 seconds
setTimeout(() => {
document.querySelector(".alert").style.display = "none";
}, 3000);
// reset form
document.getElementById("contact_form").reset();
}
const saveMsg =(Uname, email, mobile, message) =>{
var newContactForm = ContactFormDB.push();
newContactForm.set({
UserName : Uname,
Email : email,
mobile : mobile,
message : message,
});
};
const getElementVal = (id) => {
return document.getElementById(id).value;
};