-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.js
99 lines (73 loc) · 2.63 KB
/
form.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
88
89
90
91
92
93
94
95
96
97
98
var config = {
apiKey: "AIzaSyDexK17sL_1W2mShAchVwSTgc231lpUBOc",
authDomain: "t-euphoria.firebaseapp.com",
databaseURL: "https://t-euphoria.firebaseio.com",
projectId: "t-euphoria",
storageBucket: "t-euphoria.appspot.com",
messagingSenderId: "331178327824"
};
firebase.initializeApp(config);
var database = firebase.firestore();
database.settings({timestampsInSnapshots : true })
// var messageRef = database.ref('UserProfile');//creating a collection
// function validateForm() {
// var x = document.forms["myForm"]["email"].value;
// // var y = document.forms["myForm"]["phone"].value;
// if (x == "") {
// alert("Name and phone numbers required must be filled out");
// return false;
// }
// }
document.getElementById('contactForm').addEventListener('submit', submitForm);
function submitForm(e){
e.preventDefault();
var email = getInputValue('email');
var event_location = getInputValue('event_location');
var event_type = getInputValue('event_type');
var name = getInputValue('name');
var phone = getInputValue('phone');
var date = getInputValue('event_date');
var event_date = new Date (date).toDateString()
//getting input from a checkbox
var service_type = [];
var inputElements = document.getElementsByClassName('messageCheckbox');
for(var i=0; inputElements[i] ; i++){
if(inputElements[i].checked === true){
service_type.push (inputElements[i].value);
}
}
console.log(service_type);
for (var i = 0 ; i < service_type.length ; i++){
console.log(service_type[i]);
}
console.log(event_date);
saveMessage(email,event_location,event_type,name,phone,service_type,event_date)
}
function getConfirmation() {
// var retVal = ;
if( confirm("Do you still want to make a request ?") ) {
return window.location.href = "form.html";
// return true;
} else {
return window.location.href = "index.html";
// return false;
}
// console.log("true")
}
function saveMessage(email,event_location,event_type,name,phone,service_type,event_date){
// var newMessageRef = messageRef.push();
var process = database.collection('UsersRequests').add({
email:email,
event_location:event_location,
event_type:event_type,
name:name,
phone:phone,
service_type:service_type,
event_date: event_date
}).then(()=>{
getConfirmation();
});
}
function getInputValue (id){
return document.getElementById(id).value;
}