Hi,
I have set up CKEditor using an onclick event on a link as I want my users to be able to edit the content of the page by clicking on the link rather than having the editor windows open all of the time. Consequently, the CKEDITOR.replace call appears before the <textarea> as follows:
It looks like I have entered the content twice, but it is all served from my database in php so it's not really doubled.
Anyway, as a result of the CKEDITOR.replace being before the <textarea>, the save button is greyed out in the editor. I therefore want to edit the save plugin so that it nevertheless works (I know I could just use the submit button and get rid of the editor's save button but I've only really included that for testing purposes and don't want it in the final version). I was hoping you could help me get my head round the save plugin code so that I can edit it please.
The code is as follows:
Please could you tell me if my thinking is correct and answer the following questions?
1. The line var $form = editor.element.$.form; takes what is in the editor and saves it as the variable, $form.
What does the $ signify?
Is it correct to think that as this comes before the editor, there is nothing in the form, so the variable has no value?
2. if ( $form )
{try
{$form.submit();
So, if the $form variable has a value (which it doesn't), the plugin attempts to submit the form. It therefore doesn't submit the form.
There is no action for the else of the above if - can I specify that the form should submit in the else, so that it does it anyway?
3. Finally, If I am way out on 1 and 2 above, can you please help and suggest a way forward? All I want is the form to submit so that I can pick up the edited details using php's $_POST - I am sure it can't be hard but I am at a bit of a loss.
I would be ever so grateful for even the smallest of pointers - I notice that a few folk have asked similar questions and not received help, so if you can help it would at least provide a reference for others!
Thanks and best wishes,
Stu
I have set up CKEditor using an onclick event on a link as I want my users to be able to edit the content of the page by clicking on the link rather than having the editor windows open all of the time. Consequently, the CKEDITOR.replace call appears before the <textarea> as follows:
<a href="" onclick="this.style.display='none';CKEDITOR.replace('body2'); return false;">Edit this bit of content</a> <div id="body2"> <p>Draft content</p> </div> <form name="contentEditor" action="/aboutus/index.php" method="get"> <textarea style="display:none" name="body2"><p>Draft content</p></textarea> <input type="submit" value="Save changes" /> </form>
It looks like I have entered the content twice, but it is all served from my database in php so it's not really doubled.
Anyway, as a result of the CKEDITOR.replace being before the <textarea>, the save button is greyed out in the editor. I therefore want to edit the save plugin so that it nevertheless works (I know I could just use the submit button and get rid of the editor's save button but I've only really included that for testing purposes and don't want it in the final version). I was hoping you could help me get my head round the save plugin code so that I can edit it please.
The code is as follows:
(function() { var saveCmd = { modes : { wysiwyg:1, source:1 }, readOnly : 1, exec : function( editor ) { var $form = editor.element.$.form; if ( $form ) { try { $form.submit(); } catch( e ) { // If there's a button named "submit" then the form.submit // function is masked and can't be called in IE/FF, so we // call the click() method of that button. if ( $form.submit.click ) $form.submit.click(); } } } }; var pluginName = 'save'; // Register a plugin named "save". CKEDITOR.plugins.add( pluginName, { init : function( editor ) { var command = editor.addCommand( pluginName, saveCmd ); command.modes = { wysiwyg : !!( editor.element.$.form ) }; editor.ui.addButton( 'Save', { label : editor.lang.save, command : pluginName }); } }); })();
Please could you tell me if my thinking is correct and answer the following questions?
1. The line var $form = editor.element.$.form; takes what is in the editor and saves it as the variable, $form.
What does the $ signify?
Is it correct to think that as this comes before the editor, there is nothing in the form, so the variable has no value?
2. if ( $form )
{try
{$form.submit();
So, if the $form variable has a value (which it doesn't), the plugin attempts to submit the form. It therefore doesn't submit the form.
There is no action for the else of the above if - can I specify that the form should submit in the else, so that it does it anyway?
3. Finally, If I am way out on 1 and 2 above, can you please help and suggest a way forward? All I want is the form to submit so that I can pick up the edited details using php's $_POST - I am sure it can't be hard but I am at a bit of a loss.
I would be ever so grateful for even the smallest of pointers - I notice that a few folk have asked similar questions and not received help, so if you can help it would at least provide a reference for others!
Thanks and best wishes,
Stu
Re: Understanding and customising the save plugin
First of all, the order of the replace call versus the placement of the textarea doesn't matter, it only matters if the textarea is inside a form to enable the save button. I don't know why you say that it isn't enabled for you because it should work.
Second, change the method of your form to POST instead of get.
Third, you should escape the contents of the textarea.
With regards to those questions, the .form refers to the <form>, so it checks if the textarea is inside a form and then submits it
Re: Understanding and customising the save plugin
- Ho hum!
- I guess I must have done something else stupid then, because the save button is most definitely greyed out!
- yep, done that now, thanks
- good plan.
So, any thoughts on where I go from here please?
Cheers
Stu
Re: Understanding and customising the save plugin
Re: Understanding and customising the save plugin
It works!!!!
You are brilliant - thank you. Hopefully I can get it sorted and working tonight.
Really, really appreciate your help - I hope that as I gain experience I will be able to help others in the future.
Very best wishes,
Stu