This is a migrated thread and some comments may be shown as answers.

Load HTML from database to editor (PHP)

3 Answers 242 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Robin
Top achievements
Rank 1
Robin asked on 19 Feb 2013, 10:55 PM
I'm using the Kendo UI Web Editor to allow the user to add formatted content.

I then save this content to a MySQL database.

What is the correct way to load such content to the editor again to allow for further editing?

I tried
editor.value("<?=$html;?>");
and
editor.paste("<?=$html;?>");
Where $html is the string with the HTML from the MySQL-database. However this causes the editor to be blank (no content) and for the editor widget to not initialize (it is only shown as a blank textarea).

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 21 Feb 2013, 02:47 PM
Hello Robin,

Basically you should be able to paste html into the editor. I suspect that there are errors in the console, since you mentioned the Editor is not initialized at all, could you check that?

Take a look at this jsbin and compare to your code:

http://jsbin.com/igunuz/2/edit

Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Robin
Top achievements
Rank 1
answered on 26 Feb 2013, 09:03 AM
I gave it another try now, and the error in the console is 
Uncaught SyntaxError: Unexpected token ILLEGAL
I'm not able to figure out which token causes this.

In the console it looks like this token is between "ansatte" and "til å mosjonere" (first and second line), but all I can see there is a linebreak. 

Is there something I should to serverside to prepare the HTML for injection to the editor?

For this example, the HTML/JS looks like this:
var editor = $("#editor").data("kendoEditor");
        editor.value("<p><span class=\"ms-rteCustom-Text\">Målet med dette er å motivere de ansatte
til å mosjonere, delta på arrangementer, samt å profilere
XXXX.</span></p><p><span class=\"ms-rteCustom-Text\"><strong>Generelt:</strong></span></p><ul type=\"disc\"><li><span class=\"ms-rteCustom-Text\">Info here
</span>
</li></ul><p>Har du spørsmål til ordningen kontakt xxx@xxx.no</p>");
0
Robin
Top achievements
Rank 1
answered on 26 Feb 2013, 09:14 AM
In case anyone else struggles with this: the source of the error was actually the linebreak.

So serverside, doing a str_replace on \r and \n was all I needed to do to make it work in the editor again.
Tags
Editor
Asked by
Robin
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Robin
Top achievements
Rank 1
Share this question
or