4

I'm using phonegap desktop app (file is auto generated when using i click create file in the desktop app.), with atom editor and firebase with this project. To summarise my project, it is just some sort of survey so user will have to fill up some forms.

I could not get my forms detail uploaded to firebase. I am sure that firebase is connected properly, as I am able to retrieve data from firebase and display in the console. But it just could not store forms data into it.

This is my html page

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <script type="text/javascript" src="cordova.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <title>AMT Survey</title>
</head>
<body>
<a href="index.html"><img src="img/back.png"  style="width:8%;"></a><br>
<form id="amtForm">
<b style="font-size: 27px;">AMT <p></b>
<b class=fs>Screen by: </b><br><input type="text" name="screenby" id="screenby"><br>
<b class=fs>Name of client:</b> <br><input type="text" name="client" id="client"><br>
<b class=fs>Date: </b><br><input type="date" name="date" id="date"><p>
  <input type="submit" class="button" value="Submit">
  <!--<button (click)="postData(name)">submit</button>-->
  </form>

  <script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
   <script scr="main.js"></script>
   </body>
   </html>

and this is my js file

 // Initialize Firebase
 (function() {
  const config = {
  apiKey: "",
  authDomain: "",
  databaseURL: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: ""
  };
  firebase.initializeApp(config);
   }());

  //reference messages collection
  var nameRef = firebase.database().reference('name');

   // listen for form submit
   document.getElementById('amtForm').addEventListener('submit',submitForm);


   function submitForm(e){
   e.preventDefault();

   var name = getInputVal('name');
   var client = getInputVal('client');
   var date = getInputVal('date');

   saveMessage(name,client,date);
   }

   function getInputVal(id){
   return document.getElementById(id).value;
    }

   function saveMessage(name,client,date){
   var newMessageRef = nameRef.push();
   newMessageRef.set({
   name:name,
   client:client,
   date:date
   });
   }
   /*
   postData(name){
   firebase.database().ref().push({name:name});
   }
   */

These code is from a youtube video tutorial and he doesn't seem to face the same error like me. Here is the video https://www.youtube.com/watch?v=PP4Tr0l08NE

Is there anything wrong with my code? Or maybe I have the wrong setup? or maybe some other reason?

Hope this sreenshot helpscreenshot the underline is the value i have keyed in the textbox.
This shows that the data is read but somehow it does not go into firebase
FYI: the cornova.js script does not affect the connection. it is not a fatel error

enter image description here

NoobProgrammer
  • 444
  • 4
  • 21

1 Answers1

1

Did you set the read and write permissions to true?

Also change this: //reference messages collection var nameRef = firebase.database().reference('name');

To: //reference messages collection var nameRef = firebase.database().ref('name');