I tried the Korikulum method on CKEditor 4, but it writes the form twice, so I came up with this:
$(function () { setTimeout(function () { CKEDITOR.instances.MyEditor.on('beforeCommandExec', function (event) { if (event.data.name === 'save') { event.cancel();//this does not seem to prevent the form post $(MyEditor).val(CKEDITOR.instances.MyEditor.getData());//copy data from the editor to the textarea $.ajax({ type: $(editorForm).attr('method'), url: $(editorForm).attr('action'), data: $(editorForm).serialize(), success: function (data) { alert(data.message); } }); } }); }, 100);//CKEditor is heavy and needs time to initialize editorForm.submit = function (e) {//this is needed to prevent the 2nd post return false; }; });
MyEditor is a text area identifier with ckeditor class
editorForm is the identifier of the form that wraps the text area
CKEditor overrides the form.submit () function when it is initialized inside the form and event.cancel () does not seem to prevent the form from being submitted. So I had to redefine the function with a function that returns false.
EDIT: I forgot to copy the recently edited data into a text box so that it can be sent along with the rest of the form.
Dmitry
source share