I'm retrieving text from a database that is supposed to serve as the value for my CKEditor field.
Here's my code:
<script src="https://cdn.ckeditor.com/ckeditor5/34.2.0/classic/ckeditor.js"></script>
<textarea id="editor" rows="6" name="post-body" value="<?php echo html_entity_decode($post['content']) ?>"></textarea>
<script>
ClassicEditor
.create( document.querySelector( '#editor' ) )
.catch( error => {
console.error( error );
} );
</script>
However, when the page is rendered, the CKEditor field is blank; the contents of my value attribute isn't displayed.
What can be causing this? How can I fix it?
CodePudding user response:
Textarea doesn't have the attribute value
.
The content goes between <textarea>
and </textarea>
or when you want to display a placeholder you have to use the attribute placeholder
.
So either
<textarea id="editor" rows="6" name="post-body"><?php echo html_entity_decode($post['content']) ?></textarea>
or
<textarea id="editor" rows="6" name="post-body" placeholder="<?php echo html_entity_decode($post['content']) ?>"></textarea>
See Textarea on MDN
See Value attribute