CKEditor submitting empty content to the form.

 ̄綄美尐妖づ 提交于 2019-12-12 04:04:38

问题


I've started using CKEditor v3 few weeks ago.using it in a php project.i've been using it with jquery (using jquery adapter) and all this while using $.ajax (because can't handle for errors when using jquery form) to submit and i thought everything was alright .

So here pops up a case where i need to use normal form mechanism to submit the ckeditor content and all the other information of the form.
To my surprise the content was empty so i started google and apparently it's a known issue. i haven't seen any thing YET that could let me post my content to php side. so i've come up with a workaround.

I know onclick will always fire before the onsubmit so i've written this.

function returntoSubmit(){
    myForm = document.forms[0];
    myForm.elements["content"].value = $("#content").val();// note that the textarea name and id are all the same "content"

}

// html here 
 <input type="submit" value="Save" onclick="returntoSubmit()" />

that does the work for me.But truly and a little uncomfortable with this, isn't there any better method to solve this issue?

Thanks


回答1:


I'm running a large application with some nasty legacy code and needed something that worked across the whole app as non-intrusively as possible. In my case it wasn't feasible to listen for submits on each page individually, and even when I did I occasionally had race conditions where the submit still occurred before the click event code had a chance to do it's thing. The following seems to do the trick for me when ran after page load at a global scope:

for(var i in CKEDITOR.instances) {
  CKEDITOR.instances[i].on('blur', function() { this.updateElement(); });
}



回答2:


May this help

CKEDITOR.instances[content].getData()



回答3:


Just ran across this problem too... it seems that the best way to update all the textareas is:

for(var i in CKEDITOR.instances) CKEDITOR.instances[i].updateElement();

http://cksource.com/forums/viewtopic.php?f=11&t=15877




回答4:


I have actually added my own twist that works nicely as I was having trouble today with the same issue.

I used your function call, but instead do this i give my textarea the ID of ckeditor:

function returnToSubmit() {
$('#ckeditor').val(CKEDITOR.instances['ckeditor'].getData();
}



回答5:


I used this in a jquery ready event for all forms:

$('form').on('submit',function(){
  for(var i in CKEDITOR.instances) {
    CKEDITOR.instances[i].updateElement();
  }
});

Later I add another specific form submit event handler to do the actual custom submit logic for each form.



来源:https://stackoverflow.com/questions/8366392/ckeditor-submitting-empty-content-to-the-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!