Data not storing to firestore

137 views
Skip to first unread message

abraham sajan

unread,
Feb 7, 2024, 8:35:59 PM2/7/24
to Firebase Google Group
In my html project I have a form with 3 fields. I want to store the data to firestore. I connected my project to firebase perfectly. The firebase confg for data submission was written in a separate js file. 

// firebase config.

import { initializeApp } from "firebase/app";
import { addDoc, collection, getFirestore } from "firebase/firestore";

const firebaseConfig = {
  apiKey: "AIzaSyDgynWgeZiWXkalunthJOeNi2FbwNULK6U",
  projectId: "abrahamsajan-portfolio",
  messagingSenderId: "1059873599474",
  appId: "1:1059873599474:web:44b9be9caf9d5efbe5c56b",
};

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

// form submission

const form = document.querySelector(".contact-form");

form.addEventListener("submit", async (e) => {
  e.preventDefault();

  const fullName = form.querySelector("#full-name").value;
  const email = form.querySelector("#email").value;
  const message = form.querySelector("#message").value;

  try {
    const docRef = await addDoc(collection(db, "enquiries"), {
      fullName: fullName,
      email: email,
      message: message,
    });
    console.log("Document written with ID: ", docRef.id);

    alert("Form submitted successfully!");

    form.reset();
  } catch (error) {
    console.error("Error adding document: ", error);
    alert(
      "An error occurred while submitting the form. Please try again later."
    );
  }
});

Arthur Thompson

unread,
Feb 26, 2024, 3:08:10 PM2/26/24
to fireba...@googlegroups.com
Hi Abraham,

What is the error you are getting when you try to add the doc?

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/c88b49d5-fce1-4c40-9e01-771601d100bdn%40googlegroups.com.

abraham sajan

unread,
Feb 27, 2024, 12:07:15 PM2/27/24
to fireba...@googlegroups.com
Actually I don't know if it is some network issue or not. I was able to perform crud operations perfectly in the beginning but now nothing is working. There's no error or anything.

You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/yPHFOBtCzKg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/CANXaM1qQw2KpDKXokwt_CXsgkAETOPRwGxUtXM-TAoQJRoLvhQ%40mail.gmail.com.

Arthur Thompson

unread,
Feb 27, 2024, 12:40:07 PM2/27/24
to fireba...@googlegroups.com
It could be a network issue, trying another network might be a useful thing to try if possible.

You have a try/catch block where you print the error. So when the add fails you don't get the resulting error printed in the console?

Reply all
Reply to author
Forward
0 new messages