-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
109 lines (91 loc) · 3.18 KB
/
test.html
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
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form</title>
<!-- Firebase JavaScript SDK (version 8) -->
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-firestore.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
form {
max-width: 400px;
margin: 0 auto;
}
label {
display: block;
margin-bottom: 8px;
}
input,
textarea {
width: 100%;
padding: 8px;
margin-bottom: 16px;
}
button {
background-color: #4caf50;
color: white;
padding: 10px 15px;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>Contact Form</h1>
<form id="contactForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="message">Message:</label>
<textarea id="message" name="message" required></textarea>
<button type="submit">Submit</button>
</form>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyDdBq_yjdFvph0fM02jVh3_O-MZlzQViLs",
authDomain: "abitech-7d26d.firebaseapp.com",
databaseURL: "https://abitech-7d26d-default-rtdb.europe-west1.firebasedatabase.app",
projectId: "abitech-7d26d",
storageBucket: "abitech-7d26d.appspot.com",
messagingSenderId: "912772211433",
appId: "1:912772211433:web:d800f8c62d0ce631288678",
measurementId: "G-G8JMCKRZTT"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Initialize Firestore
var db = firebase.firestore();
var contactForm = document.getElementById('contactForm');
contactForm.addEventListener('submit', function (event) {
event.preventDefault();
// Get form data
var formData = {
name: document.getElementById('name').value,
email: document.getElementById('email').value,
message: document.getElementById('message').value,
};
// Add data to Firestore
db.collection('contacts').add(formData)
.then(function (docRef) {
console.log("Document written with ID: ", docRef.id);
alert("Your message has been sent!");
contactForm.reset();
})
.catch(function (error) {
console.error("Error adding document: ", error);
alert("Error sending message. Please try again later.");
});
});
</script>
</body>
</html>