-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
59 lines (50 loc) · 1.55 KB
/
script.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
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyAPmt2djM1NmBWKGH1mCM5_-28qA9ZW3UQ",
authDomain: "cbgddc-website.firebaseapp.com",
databaseURL: "https://cbgddc-website-default-rtdb.firebaseio.com",
projectId: "cbgddc-website",
storageBucket: "cbgddc-website.appspot.com",
messagingSenderId: "1048860190995",
appId: "1:1048860190995:web:e70c61a1055fa429ddd2e6",
measurementId: "G-VSFBVQPP8J"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
//Reference messages
var messagesRef = firebase.database().ref('messages');
//Listen to submit
document.getElementById('contactForm').addEventListener('submit', submitForm);
//Function to submit form
function submitForm(e) {
e.preventDefault();
let name = getInput('name');
let email = getInput('email');
let member = document.getElementById('member').checked;
let message = getInput('message');
saveMessage(name, email, member, message);
success();
}
//Function to get input values
function getInput(id) {
return document.getElementById(id).value;
}
//Save messages
function saveMessage(name, email, member, message) {
newMessageRef = messagesRef.push();
newMessageRef.set({
name: name,
email: email,
member: member,
message: message
});
}
function success() {
let success = document.getElementById('success').style;
success.display = 'block';
setTimeout(() => {
success.display = 'none';
}, 4000);
document.getElementById('contactForm').reset();
}