Mobile first, responsive contact from that sends data to a firebase database
bradtraversy / firebasecontact Goto Github PK
View Code? Open in Web Editor NEWSimple firebase contact form
Simple firebase contact form
how do you solve it?
Uncaught TypeError: firebase.database is not a function
at main.js:14
i am trying to use your script on my app for creating cotact and booking form. my problem is only 1 code will work and other wont work. i changed the ids still wont work. can you please help.
i havent fully editted them for my needs. first need to work.
thank you
heres my code
booking form//
// Reference boks collection
var boksRef = firebase.database().ref('boks');
// Listen for form submit
document.getElementById('contactForms').addEventListener('submit', submitForm);
// Submit form
function submitForm(e){
e.preventDefault();
// Get values
var name = getInputVal('name');
var company = getInputVal('company');
var email = getInputVal('email');
var phone = getInputVal('phone');
var message = getInputVal('message');
// Save bok
savebok(name, company, email, phone, message);
// 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('contactForms').reset();
}
// Function to get get form values
function getInputVal(id){
return document.getElementById(id).value;
}
// Save bok to firebase
function savebok(name, company, email, phone, message){
var newbokRef = boksRef.push();
newbokRef.set({
name: name,
company:company,
email:email,
phone:phone,
message:message
});
}
//contact form
// Initialize Firebase (ADD YOUR OWN DATA)
// Reference boks collection
var bokesRef = firebase.database().ref('bokes');
// Listen for form submit
document.getElementById('contacted').addEventListener('submit', submitForms);
// Submit form
function submitForms(e){
e.preventDefault();
// Get values
var name = getInputVal('name');
var company = getInputVal('company');
var email = getInputVal('email');
var phone = getInputVal('phone');
var message = getInputVal('message');
// Save bok
saveboke(name, company, email, phone, message);
// 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('contacted').reset();
}
// Function to get get form values
function getInputVal(id){
return document.getElementById(id).value;
}
// Save bok to firebase
function saveboke(name, company, email, phone, message){
var newbokeRef = bokesRef.push();
newbokeRef.set({
name: name,
company:company,
email:email,
phone:phone,
message:message
});
}
hi i am using your code, my problem is once the submit button is pressed it sends me back to the homepage. do you know how to get the page to stay on the contact page and not divert to different page,
thank you for the code
Line 10 in 6c65cb3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.