0

This question already has answers here: Rule entries duplicates firebase not working (1 answer) Firebase android : make username unique (3 answers) What Firebase rule will prevent duplicates in a collection based on other fields? (1 answer) Firebase unique field value (1 answer) Your post has been associated with similar questions. If these questions don’t resolve your question, ask a new one.

Closed 6 hours ago.

(Private feedback for you)

I'm completely new to firebase. I'm creating a basic contact form for my application and connected that to the firebase database. I don't have any authentication for my application. . I have set all the rules to True . I want to prevent duplication, if there exists email in database I want to display an error message.

Below is my code which I have tried

var config = {
 apiKey: "AIzaSyDA3u4bIIYHHTgB8u11NxtRVh9MOWe0jJQ",
 authDomain: "g-bb8b1.firebaseapp.com",
 databaseURL: "https://g-bb8b1-default-rtdb.firebaseio.com",
 projectId: "g-bb8b1",
 storageBucket: "g-bb8b1.appspot.com",
 messagingSenderId: "739938707423",
};
firebase.initializeApp(config);


// Reference messages collection
var messagesRef = firebase.database().ref('Email');

// Listen for form submit
document.getElementById('contactForm').addEventListener('submit', submitForm);


// Submit form
function submitForm(e){
 e.preventDefault();

 //Get value
 var email = getInputVal('email');

 // Save message
 saveMessage(email);

 // Show alert
 document.querySelector('.alert').style.display = 'block';

 // Hide alert after 3 seconds
 setTimeout(function(){
   document.querySelector('.alert').style.display = 'none';
 },3000);

 // Clear form
 document.getElementById('contactForm').reset();
}

// Function to get form value
function getInputVal(id){
 return document.getElementById(id).value;
}

// Save message to firebase
function saveMessage(email){
 var newMessageRef = messagesRef.push();
 newMessageRef.set({
   email: email
 });
}   ```

I looked for some solutions but it didn't work
  • Don't repost the same question multiple times please. If you've tried the approach I explained in my comment on your previous question, and explained in the links I gave there, show what you've done with that. If you have a specific question about that approach, leave a comment on that post please. At best it will be closed, but it may get you banned from the site. – Frank van Puffelen Sep 11 '21 at 23:19

0 Answers0