-
Notifications
You must be signed in to change notification settings - Fork 0
/
contactmain.js
87 lines (72 loc) · 2.27 KB
/
contactmain.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var firebaseConfig = {
apiKey: "AIzaSyC8LmW7whQc2AhY37VtoYt9Er5VpDjALLs",
authDomain: "contactus-fe046.firebaseapp.com",
projectId: "contactus-fe046",
storageBucket: "contactus-fe046.appspot.com",
messagingSenderId: "609105220014",
appId: "1:609105220014:web:d7ccc27263024d66b5b83f",
measurementId: "G-Q27F7ZQXKH"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
var firestore = firebase.firestore()
//variable to access database collection
const db = firestore.collection("formdata")
//get submit form
let submitButton = document.getElementById('submit')
// Create event listener to allow form submission
submitButton.addEventListener("click", (e) =>{
//prevent default form submission behavior
e.preventDefault()
// get form values
let name = document.getElementById('name').value
let email = document.getElementById('email').value
let phone = document.getElementById('phone').value
let subject = document.getElementById('subject').value
let symptom = document.getElementById('symptom').value
// save form data to firebase
db.doc().set({
name: name,
email: email,
phone: phone,
subject: subject,
symptom: symptom
}).then( () => {
console.log("Data Saved ")
}).catch((error) => {
console.log(error)
})
//alert
alert("Your query has been saved ")
})
/*
//Reference subject collection
var messageRef = firebase.database().ref('message');
document.getElementById('contact-us').addEventListener('Get Consultation', submitForm);
// Submit form
function submitForm(e) {
e.preventDefault();
var name = getInputVal('name');
var email = getInputVal('email');
var phone = getInputVal('phone');
var subject = getInputVal('subject');
var symptom = getInputVal('symptom');
// Save Message
saveMessage(name, email, phone, subject, symptom);
}
// Function to get form values
function getInputVal(id) {
return document.getElementById(id).value;
}
// Save message to firebase
function saveMessage(name, email, phone, subject, symptom) {
var newMessageRef = messageRef.push();
newMessageRef.set({
name: name,
email: email,
phone: phone,
subject: subject,
symptom: symptom
});
}
*/