Ckeditor Undefined no Nodejs

Asked

Viewed 14 times

-1

I’m studying Nodejs and I have a problem with Ckeditor.

I am unable to pass the text information written within the textarea to the backend. He creates the id within the materials, but the content of the editor1 comes as undefined.

I’m reading the documentation and I haven’t been able to figure out how to solve it yet (since I don’t have enough wit yet). I’ve tried the request of editor1 for params and headers to see if that was it, but it didn’t work either.

Follow the HTML code:

<div class="entry">
    <script src="https://cdn.ckeditor.com/4.9.1/standard/ckeditor.js"></script>
    <h1>Teste</h1>
    <div class="body">
        <form action="http://localhost:3333/post-blog/cadastrar" method="post">
            <textarea name="editor1"></textarea>
            <button class="btn-cadastro">Cadastrar</button>
        </form>
        <script>
            CKEDITOR.replace('editor1');
        </script>
    </div>
</div>

And the Nodejs code:

const express = require('express');
const {
  v4: uuidv4
} = require('uuid');

const app = express();

app.use(express.json());

const materias = [];
app.post('/post-blog/cadastrar', (request, response) => {
  const {
    editor1
  } = request.body;
  const materia = {
    id: uuidv4(),
    conteudo: editor1
  };

  materias.push(materia);
  return console.log(editor1);
})
app.listen(3333);
  • Try adding a name="myform" to the form and tag textArea add the attribute form="myform" and see if it solves...

  • Still, it’s like Undefined. But thanks for the help anyway.

  • remove app.use(express.json()); resolve? Later on I can even try to debug your code which is even simple to replicate...

  • Typeerror: Cannot destructure Property 'editor1' of 'request.body' as it is Undefined. Now gave this error, it can not disrupt something Undefined

  • I forgot to tell you, use app.use(express.urlencoded({extended: true})) and test again

  • OPA!!! It worked very well Boy!. Now I will study the reason for this, thank you very much!!

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.