-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 tagtextAreaadd the attributeform="myform"and see if it solves...– Cmte Cardeal
Still, it’s like Undefined. But thanks for the help anyway.
– Bruno Passos
remove
app.use(express.json());resolve? Later on I can even try to debug your code which is even simple to replicate...– Cmte Cardeal
Typeerror: Cannot destructure Property 'editor1' of 'request.body' as it is Undefined. Now gave this error, it can not disrupt something Undefined
– Bruno Passos
I forgot to tell you, use
app.use(express.urlencoded({extended: true}))and test again– Cmte Cardeal
OPA!!! It worked very well Boy!. Now I will study the reason for this, thank you very much!!
– Bruno Passos