-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
46 lines (35 loc) · 1.19 KB
/
main.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
// Your web app's Firebase configuration
// Reference Messages collection
/*Once you added your firebase configuration, uncomment this*/
// var messagesRef = firebase.database().ref('messages');
// Listen for form Submit
document.getElementById("contactForm").addEventListener('submit',submitForm);
function submitForm(e) {
e.preventDefault();
var name = getInputVal('name');
var com = getInputVal('company');
var em = getInputVal('email');
var ph = getInputVal('phone');
var msg = getInputVal('message');
//Save Message
saveMessage(name,com,em,ph,msg);
//Show Alert
setTimeout(function() {document.querySelector('.alert').style.display = 'block' },3000);
//Clear form
document.getElementById("contactForm").reset();
}
//Function to get Form Values
function getInputVal(id) {
return document.getElementById(id).value;
}
//Save Message to FireBase
function saveMessage(name, company, email, phone, message) {
var newMessageRef = messagesRef.push();
newMessageRef.set({
name: name,
company: company,
email: email,
phone: phone,
message: message
});
}