Forked from sharon-rozinsky/firebase-by-example-realtime-db.js
Created
October 8, 2018 01:41
-
-
Save spac3unit/3e59ee3a0dacac940dc43913d91ba19b to your computer and use it in GitHub Desktop.
firebase-by-example: Realtime DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Credits to the awesome Brad Traversy, check out this video at: https://www.youtube.com/watch?v=PP4Tr0l08NE | |
| var messagesRef = firebase.database().ref('messages'); | |
| document.getElementById('contactForm').addEventListener('submit', submitForm); | |
| function submitForm(e) { | |
| e.preventDefault(); //prevent reloading the html page | |
| var name = getInputVal('name'); | |
| var email = getInputVal('email'); | |
| var company = getInputVal('company'); | |
| var phone = getInputVal('phone'); | |
| var message = getInputVal('message'); | |
| saveMessageToRealtimeDB(name, company, email, phone, message); | |
| saveFormToFirestore(name, company, email, phone, message); | |
| document.querySelector('.alert').style.display = 'block'; | |
| setTimeout(function () { | |
| document.querySelector('.alert').style.display = 'none'; | |
| }, 3000); | |
| document.getElementById('contactForm').reset(); | |
| } | |
| function getInputVal(id) { | |
| return document.getElementById(id).value; | |
| } | |
| function saveMessageToRealtimeDB(name, company, email, phone, message) { | |
| var newMessageRef = messagesRef.push(); | |
| newMessageRef.set({ | |
| name: name, | |
| company: company, | |
| email: email, | |
| phone: phone, | |
| message: message | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment