Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const firestore = firebase.firestore();
- const documentRef = firestore.collection("forms");
- function saveFormToFirestore(name, company, email, phone, message) {
- documentRef.doc(name).set({
- name: name,
- company: company,
- email: email,
- phone: phone,
- message: message
- }).then(function () {
- console.log("Added document to collection");
- }).catch(function (error) {
- console.error("Error while adding document: ", error);
- });
- }
- document.getElementById("queryFirestore").addEventListener('click', function (e) {
- var nameToQuery = getInputVal('nameToQuery');
- documentRef.doc(nameToQuery).get()
- .then(function (doc) {
- if (doc.exists) {
- document.getElementById('firestoreQueryResult').textContent = JSON.stringify(doc.data());
- } else {
- document.getElementById('firestoreQueryResult').textContent = "No document found for that name";
- }
- document.getElementById('nameToQuery').textContent = "";
- }).catch(function (error) {
- console.error("Error while getting document: ", error);
- });
- });
Add Comment
Please, Sign In to add comment