Hello FCK,
Hope somebody can help... I've created a series of FCK editor text areas within a form. When the form is submitted a client side javascript form validation process is started. Of course I found out that you can't validate FCK editor fields in the normal way but rather you need to rely on the API once the editor is loaded.
I've searched the forum and found out that I need to use oEditor.GetXHTML(true):
http://www.fckeditor.net/forums/viewtopic.php?f=6&t=7120&p=18975&hilit=validation#p18975
The only problem is the browser then complains that the API is undefined... digging into this further I've tested whether the API exists via this piece of javascript:
if (typeof(FCKeditorAPI)!=='undefined') { alert("API Not Defined"); } else { alert("All good") }
It of course doesn't exist. Now I've again tried various ways of creating the editor... firstly by creating the instance via asp as well as replacing a text area via Javascript neither seem to load up the required API.
Embedding FCK Editor Version One:
<SCRIPT language=JavaScript type=text/JavaScript> // global function caller to validate form function validForm(){ alert ("hello world"); if (typeof(FCKeditorAPI)!=='undefined') { alert("API Not Defined"); } else { alert("All good") } if ( radChk ('adminForm','changeModule','Please state the changes to the module you would like to make.')&& hasVal ('adminForm','changeDefDoc','Please state what impact the changes is likely to have on the definitive document.')&& hasVal ('adminForm','changeDefDoc','Please say something!') ) { return true;} else {return false;} } </SCRIPT> <form id="adminForm" name="adminForm" method="post" action="minorModCat1.asp?step=step4" onsubmit="return validForm()"> ... <td colspan="4"> <% 'sBasePath = "/fds/FCKEditor/" 'Dim oFCKeditor 'Set oFCKeditor = New FCKeditor 'oFCKeditor.BasePath = sBasePath 'oFCKeditor.Value = changeDefDoc 'oFCKeditor.Height = 200 'oFCKeditor.ToolbarSet = "Basic" 'oFCKeditor.Config("SkinPath") = "/fds/FCKeditor/editor/skins/office2003/" 'oFCKeditor.Create "changeDefDoc" %> </td> </form>
Embedding FCK Editor Version Two:
<script type="text/javascript" src="/fds/FCKEditor/fckeditor.js"></script> <script type="text/javascript"> window.onload = function() { var oFCKeditor = new FCKeditor( 'MyTextarea' ) ; oFCKeditor.BasePath = "/fds/FCKeditor/" ; oFCKeditor.ReplaceTextarea() ; FCKeditor_OnComplete() } function FCKeditor_OnComplete() { } </script> <script type="text/javascript" src="javascript/valid.js"></script> <SCRIPT language=JavaScript type=text/JavaScript> // global function caller to validate form function validForm(){ alert ("hello world"); if (typeof(FCKeditorAPI)!=='undefined') { alert("API Not Defined"); } else { alert("All good") } if ( radChk ('adminForm','changeModule','Please state the changes to the module you would like to make.')&& hasVal ('adminForm','changeDefDoc','Please state what impact the changes is likely to have on the definitive document.')&& hasVal ('adminForm','myTextarea','Please say something!') ) { return true;} else {return false;} } </SCRIPT> <form id="adminForm" name="adminForm" method="post" action="minorModCat1.asp?step=step4" onsubmit="return validForm()"> ... <td colspan="4"><textarea id="MyTextarea" name="MyTextarea"></textarea></td> ... </form>
I'm pretty sure if I could only use the API I'd be able to follow the forum post to its logical conclusion of allowing me to validate against these fields but I can't for the life of me access the API :{
Somebody please please help
Re: form validation and FCK
In case you still have the problem mentioned. Try this. On the page hosting the fckeditor add this javascript function.
function FCKeditor_OnComplete(editorInstance)
{
alert( editorInstance.Name );
}
after that you will be able to access the editors contents using the javascript API.
var oEditor = FCKeditorAPI.GetInstance(instancename);
var contents = oEditor.GetXHTML(true);
alert(contents);
Hope this helps.
Re: form validation and FCK
I must be missing exactly where to place the code.
Re: form validation and FCK
SO ,
var oEditor = FCKeditorAPI.GetInstance('keywords');// note keywords is the name of the new FCKeditor and has to be quoted
var contents = oEditor.GetXHTML(true);
the value of contents can then be validated as you normally would in any JS function.
Re: form validation and FCK
if ( typeof ( FCKeditorAPI ) == 'defined' ) { // call if defined ##
var oEditor = FCKeditorAPI.GetInstance('instancename');
var instancename = oEditor.GetXHTML(oEditor.FormatOutput);
}