fckeditor ajax提交表单为空解决方案(摘自FCK官网)
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/