Я пытаюсь подключить свое веб-приложение к моей базе данных Firebase, но оно не будет добавлять информацию к нему.Я хотел бы, чтобы пользователь вводил информацию в систему, и эта информация сохранялась в базе данных под названием «appts»:
Функция JS:
var config = {
apiKey: "____________",
authDomain: "southern-motors.firebaseapp.com",
databaseURL: "https://southern-motors.firebaseio.com",
projectId: "southern-motors",
storageBucket: "southern-motors.appspot.com",
messagingSenderId: "852338882104"
};
firebase.initializeApp(config);
var messagesRef = firebase.database().ref('appts');
document.getElementById('appts').addEventListener('submit', addAppt);
function addAppt(e) {
e.preventDefault();
var inputName = document.getElementById("customerName").value;
var inputEmail =
document.getElementById("customerEmail").value.toLowerCase();
var inputPhone = document.getElementById("customerPhone").value;
var inputDate = document.getElementById("customerDate").value;
messagesRef.push({
name: inputName,
email: inputEmail,
phone: inputPhone,
date: inputDate
}).then(function() {
console.log("Document successfully written!");
location.reload();
})
.catch(function(error) {
console.error("Error writing document: ", error);
});
}
Форма ввода:
<div class="contact-form">
<form id="appts"
action="https://formspree.io/MYEMAIL" method="POST">
<label>Name: </label><input id="customerName" class ="form-control"
type="text" name="Name of Customer" required></input>
</br>
<label>Email Address: </label><input id="customerEmail" class="form-
control" type="email" name="Email Address" required></input>
</br>
<label>Phone no.: </label><input id="customerPhone" class ="form-
control" type="number" name="Phone No." required></input>
</br>
<label>Date & Time of Test Drive: </label><input id="customerDate"
class ="form-control" type="datetime-local" name="Date & Time of Test Drive"
required></input>
</br>
<input type="submit" value="Submit">
</form>
</div>
Аналогичная функция «зарегистрировать пользователя» работает в другой форме, поэтому я не уверен, почему это не работает.Все предложения приветствуются.