-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
36 lines (30 loc) · 1.23 KB
/
index.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
// Get a reference to the Firebase Realtime Database
var database = firebase.database();
// Get a reference to the contact form
var contactForm = document.getElementById("contact_form");
// Add an event listener to the contact form to listen for form submissions
contactForm.addEventListener("submit", function(event) {
// Prevent the default form submission behavior
event.preventDefault();
// Get the values from the contact form
var name = contactForm.querySelector("[name='Name']").value;
var email = contactForm.querySelector("[name='Email']").value;
var subject = contactForm.querySelector("[name='Subject']").value;
var message = contactForm.querySelector("[name='Message']").value;
// Save the user's input to the Firebase Realtime Database
database.ref('messages').push({
name: name,
email: email,
subject: subject,
message: message
})
.then(function() {
// If the data was saved to the database successfully, show a success message
alert("Your message was sent successfully!");
contactForm.reset();
})
.catch(function() {
// If there was an error saving the data to the database, show an error message
alert("There was an error sending your message. Please try again later.");
});
});