Skip to main content
PHP HTML Editor

JavaScript API

Every editor rendered by PHP is a RichTextEditor instance. Get it by the editor's name:

var editor = PhpHtmlEditor.get('Body');
CallDescription
editor.getHTMLCode()The current HTML.
editor.setHTMLCode(html)Replaces the content.
editor.insertHTML(html)Inserts at the caret.
editor.getPlainText()The content as text.
editor.execCommand(name)Runs a command, for example "bold" or "insertgallery".
editor.setReadOnly(true|false)Switches editing off or on.
PhpHtmlEditor.openFileManager('Body')Opens the file manager of an editor from your own button.
editor.focus()Moves the keyboard focus into the editor.
editor.attachEvent(name, fn)Listens to editor events such as "change" and "ready".

The form field is kept in sync, so a normal form post needs no script. To save with Ajax, send the form with fetch(location.href, { method: 'POST', body: new FormData(form) }) and read it on the server with posted().

Every option of the editor can be set from PHP through $editor->config (or SetConfig() in the classic API). The full list is in the RichTextEditor documentation.