Home > Back-end >  CK Editor doesn't send data to Firebase Database Empty
CK Editor doesn't send data to Firebase Database Empty

Time:02-23

have created a Web Form to upload data(Rich Text) to Firebase Database,

But sometimes data is entered to Database and other Times the Fields in the Database is completely Empty. Can Anyone suggest me the solution as I am new to Web Dev.

Here is my WebForm Code (Rich Text is only in Description):

<script>
    CKEDITOR.replace( 'quote' );
  // Initialize Firebase
  var database = firebase.database();
  var quote;

  function getdata(){
    quote = document.getElementById('quote').value;
  }
    document.getElementById('submit').onclick = function(){
    getdata();
    firebase.database().ref("quoteday/quotes").set({
        Data: quote,
    })
  }
  document.getElementById('delete').onclick = function(){
      firebase.database().ref("quoteday/").remove();
  }

</script>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
      <!----======== CSS ======== -->
      <link rel="stylesheet" href="style.css">
      <script src="//cdn.ckeditor.com/4.17.2/full/ckeditor.js"></script>
</head>
<body>
    <div >
        <label for="title">Quote day</label>
        <textarea  id="quote" name="quote" rows="3"
         data-form-field="Message" placeholder="" autofocus=""
        style="display: none;"></textarea>
    </div>
    <div><button id="submit">Submit/Update</button></div>
    <div><button id="delete">Delete</button></div>    
  

</body>
</html>

enter image description here

CodePudding user response:

Because your textarea is empty, you have to type CKEDITOR.instances.quote.updateElement(); before get element value

Updates the element that was replaced by the editor with the > current data available in the editor.

Note: This method will only affect those editor instances created with the CKEDITOR.ELEMENT_MODE_REPLACE element mode or inline instances bound to
elements.

function getdata(){
CKEDITOR.instances.quote.updateElement();
quote = document.getElementById('quote').value;
}

If it still doesn't work, you can test this block as below

 firebase.database().ref("quoteday/quotes").set({
    Data: 'Test Data',
})

and then check your database, if Test Data saved or not ?

  • Related