Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a Firebase Form?

I am using Firebase for a website page. How would I create a form with Firebase? And the data be stored in a database? There doesn't seem to be any good tutorials out there. I am new to Firebase.

like image 933
LDY Web Design Avatar asked Dec 23 '16 16:12

LDY Web Design


People also ask

Is Firebase for free?

Firebase offers a no-cost tier pricing plan for all its products. For some products, usage continues at no cost no matter your level of use. For other products, if you need high levels of use, you'll need to switch your project to a paid-tier pricing plan. Learn more about Firebase pricing plans.

How do I create a database in Firebase?

All Firebase Realtime Database data is stored as JSON objects. You can think of the database as a cloud-hosted JSON tree. Unlike a SQL database, there are no tables or records. When you add data to the JSON tree, it becomes a node in the existing JSON structure with an associated key.


1 Answers

Firebase database is more like a storage for your data objects. So all you need is build a JavaScript object from the form values and send to Firebase on submit.

Check this CodePen. Focus on the New Activity section. You will see how you can build objects from your form values and send to Firebase.

For instance, you have a form in your html:

<form id='myForm'>
  <input id='title' type='text' />
  <input id='description' type='text' />
  <input type='submit' />
</form>

And in your JavaScript file you can do this:

// Listen to the form submit event
$('#myForm').submit(function(evt) {

  // Target the form elements by their ids
  // And build the form object like this using jQuery: 
  var formData = {
    "title": $('#title').val(),
    "description": $('#description).val(),
  }

  evt.preventDefault(); //Prevent the default form submit action
  
  // You have formData here and can do this:
  firebase.initializeApp(config); //Initialize your firebase here passing your firebase account config object
  firebase.database().ref('/formDataTree').push( formData ); // Adds the new form data to the list under formDataTree node
})

Hope this helps

like image 142
El'Magnifico Avatar answered Oct 14 '22 00:10

El'Magnifico