首页 > javasrcipt > fckeditor ajax提交表单为空解决方案(摘自FCK官网)

fckeditor ajax提交表单为空解决方案(摘自FCK官网)

2009年6月23日 发表评论 阅读评论

The editor’s content is empty when submitting the editor’s surrounding form by ajax. What is wrong?

This problem is caused by a missing call of the function FCK.UpdateLinkedField(). By submitting the editor’s surrounding form with an ajax function the values of all form elements are collected in a javascript object (some kind of an array). At this time the value of the hidden field that usually contains the editor’s html output is empty, because the editor’s surrounding form wasn’t submitted for real, you can call it a simulated submit. The workaround is to call the FCK.UpdateLinkedField() function before submitting the form. Either you call it directly before the ajax collect function or in the onClick attribute of the submit button. For general use, even if you have more than one FCKeditor instance, I wrote the following hack to solve the problem.

// Some Class
function MyClass()
{
this.UpdateEditorFormValue = function()
{
for ( i = 0; i < parent.frames.length; ++i )
if ( parent.frames[i].FCK )
parent.frames[i].FCK.UpdateLinkedField();
}
}
// instantiate the class
var MyObject = new MyClass();

Now can call this method in the onSubmit attribute of the editor’s surrounding form before calling the ajax collecting function:

<form ... onSubmit="MyObject.UpdateEditorFormValue(); Ajax.Collect(); return false;">

NOTE: the previous syntax won’t work if using VisualStudio 2005 and Atlas and IE. It will be ok to use:

<form ... onSubmit="MyObject.UpdateEditorFormValue(); return true;">

Or you’ll do it in the onClick attribute of the submit button, which is also called before the onSubmit event: <input type=”submit” … onClick=”MyObject.UpdateEditorFormValue();” /> Edited by heiligkind ( hollo@heiligkind.de ) 17 August 2006

A german version can be found at: http://blog.heiligkind.de/category/nutzliches/

分类: javasrcipt 标签: , ,
  1. raul
    2009年7月25日20:00 | #1

    thank you so much!

  2. 2009年8月6日12:08 | #2

    Wow! Thank you! I always wanted to write in my site something like that. Can I take part of your post to my blog?

  3. jemo
    2009年8月17日19:10 | #3

    Of course you can

  4. 2009年10月27日02:32 | #4

    thanks !! very helpful post!

  5. 2010年2月21日01:07 | #5

    春节快乐啊^_^兄弟

  1. 2009年6月23日22:44 | #1