K.Suthagar
K.Suthagar

Reputation: 2306

How to Set inner data to CKEDITOR using PHP

I am using CKEDITOR for the advanced Post Insert purpose, when i am going to update a Post then i want to fetch text to CKEDITOR from the database. So how can i set the value to CKEDITOR?

Here is the Code which i tried(Failed),

 <script>
 // Replace the <textarea id="editor1"> with a CKEditor
 // instance, using default configuration.
 CKEDITOR.replace('post_value');
 CKEDITOR.instances['editor1'].setData(<?php echo $obj->postdata; ?>);
 </script>

Upvotes: 2

Views: 1383

Answers (2)

Wizard
Wizard

Reputation: 3151

<script>
CKEDITOR.replace('editor1');
CKEDITOR.instances.editor1.on('instanceReady', function(evt) {              
    evt.editor.setData('<?php echo $obj->postdata; ?>');
});
</script>

or

<textarea id="editor1"><?php echo $obj->postdata; ?></textarea>
.
.
.
<script>
CKEDITOR.replace('editor1');
</script>

Either way, make sure the script comes after textarea.

Upvotes: 0

charlietfl
charlietfl

Reputation: 171669

The instance key should be the same as the element ID

Try changing:

CKEDITOR.instances['editor1'].setData(<?php echo $obj->postdata; ?>);

to

CKEDITOR.instances['post_value'].setData(<?php echo $obj->postdata; ?>);

This assumes that $obj->postdata; returns an html string also

Upvotes: 1

Related Questions