Hi,
I'm having real problems at the moment!
I'm writing a small web-app in php, sql and using jquery.
Using the jquery plugin I'm able to display a div containing data (i.e. data is readonly) and on clicking an 'edit' button, I'm able to replace that div with an instance of ckeditor and edit the post. So far so good.
The problem is that no matter what I try, I can't get the ckeditor to post the data!
My error checking tells me that the ckeditor fields are posting blank data. I suspect that isn't the case as if I replace a textarea it works fine!
What seems to be happening (and I've seen this by running an 'alert') is that when ckeditor replaces the div, it doesn't pick up the 'name' attribute.
Can someone please advise my how to set the 'name' of the editor when it's instantiated? I've tried adding "name : 'myname'" into the config (alongside skin & other variables) but it's just not being picked up!
Thanks in advance for any assistance.
I'm having real problems at the moment!
I'm writing a small web-app in php, sql and using jquery.
Using the jquery plugin I'm able to display a div containing data (i.e. data is readonly) and on clicking an 'edit' button, I'm able to replace that div with an instance of ckeditor and edit the post. So far so good.
The problem is that no matter what I try, I can't get the ckeditor to post the data!
My error checking tells me that the ckeditor fields are posting blank data. I suspect that isn't the case as if I replace a textarea it works fine!
What seems to be happening (and I've seen this by running an 'alert') is that when ckeditor replaces the div, it doesn't pick up the 'name' attribute.
Can someone please advise my how to set the 'name' of the editor when it's instantiated? I've tried adding "name : 'myname'" into the config (alongside skin & other variables) but it's just not being picked up!
Thanks in advance for any assistance.

Re: Problem with setting field name
Re: Problem with setting field name
Sorry, I'm a js newb! Can you explain a little more what you mean please?
Re: Problem with setting field name
If you want to submit some content back to the server you might have to create a form and add the inputs that you want to submit. CKEditor doesn't create such inputs.
Re: Problem with setting field name
If you could just point me at a specific example to examine that might do this, I'd be very grateful!
Re: Problem with setting field name
I'm now using ckeditor to post html values into the db.
If I replace a textarea with ckeditor, it posts ok, because it picks up the name of the textarea and posts the values.
The problem is that textareas don't render the code, so I see lots of html tags. As such I'm displaying a div with the initial content when in 'read' mode, then via jquery I'm making all fields editable - in the case of ckeditor I'm creating an instance for editing.
Which function/tool/option should I be calling to make this work/post back to the text area? Can you point me at a specific piece of documentation/example that will help me learn, please?
Thanks
Re: Problem with setting field name
When you want to save the content, read the data of the instance and assign it to a hidden input.
Something like
var value= editor.getData(); var input = document.createElement('input'); input.type='hidden'; input.value = value; input.name = 'myField'; form.appendChild(input);Re: Problem with setting field name
I was re-reading last night and wondering if it was getData() I needed to use!
The html is pretty simple - just basic formatting stuff, so hopefully there won't be too many problems!
Thanks for your help!
Re: Problem with setting field name
$('.copy_field').each(function(){ $(this).ckeditor() });var field = $(this).attr('name') //get the name of the ckEditor instance var newCopy= $(this).editor.getData(); //get the value of that instance** $(':input[name=field]').val(newCopy) //find an input with the same name as the ckEditor instance, set the value to that of the new data inputtedhttp://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#name
$('.copy_field').each(function(){ var field_name = $(this).attr('name'); //returns name of div successfully alert(field_name) //puts name of div in variable, triggers alert $(this).ckeditor({ name: field_name //assigns that name to name of instance** }); alert(CKEDITOR.name); //returns name of instance });Re: Problem with setting field name
Re: Problem with setting field name
Re: Problem with setting field name
Re: Problem with setting field name
I've just had a thought that I'm going to try out - I may still need to come back to you on this!
Re: Problem with setting field name
This works for multiple divs with editors assigned to them. All you need to do is give all divs the same class (I used "content_block").
function submit_form(form) { // updates all the divs with current CKEditor content for ( instance in CKEDITOR.instances ) { CKEDITOR.instances[instance].updateElement(); } // cycles through every div with class "content_block" // and adds a hidden input to the form $('div.content_block').each(function() { $('#'+form).append("<input type='hidden' name='"+$(this).attr('id')+"' value='"+$(this).html()+"' />"); }); // submits form document.forms[form].submit() }// Something like this in you your document ready // can be used to trigger the function $('#save').click(function(){ submit_form("Form"); });Re: Problem with setting field name
Thank you all so much for your help.
Here is the final working code. I hope it helps someone!
//define url for form submission & reset //requires identified (isbn) to display/update correct data var url = '<?php echo $_SERVER["PHP_SELF"].'?isbn='.$edition['edition_isbn13'];?>'; $(document).ready(function(){ //make form editable //i.e. convert divs into ckEditor instances //when you click the edit button $(':button#edit').click(function(){ //find the divs with a class 'copy_field' $('.copy_field').each(function(){ //get the name from the div and apply it to the ckEditor var field_name = $(this).attr('name'); //alert(field_name) $(this).ckeditor({ name: field_name }); }); //when the page is in edit mode, you don't need an 'edit button //you need a save button and a 'reset' or 'cancel' button. //hide edit, show 'save' and 'reset' $(this).hide(); $('#save_button').show(); $('#reset').show(); }); //if they click 'reset', reload the original data //url is defined at the top of the script $(':button#reset').click(function(){ $('.ui-tabs-panel:visible').load(url); }); //changes have been made - they click the 'save'/'submit' button $('#admin_form').submit(function(e){ //prevent the page from loading normally e.preventDefault(); //update the original element for ( instance in CKEDITOR.instances ) { CKEDITOR.instances[instance].updateElement(); } //find the updated divs with the class 'copy_field' (as per 'for' loop above) //create new form elements for posting $('div.copy_field').each(function() { $('#admin_form').append('<input type="hidden" name="'+$(this).attr('id')+'" value="'+$(this).html()+'"/>'); }); //perform the ajax query var str = $(this).serialize(); $.ajax({ type: "POST", url: url, data: str, success: function(data) { $('.ui-tabs-panel:visible').html(data); // update the DIV }, error: function(e, xhr) { console.log(e); } }); }); //end admin submit function });Re: Problem with setting field name
The original code caused issues when posting copy with an apostrophe or single quote mark - it truncated anything after that.
I've amended it (mainly by switching quotes around) to read thus:
$('div.copy_field').each(function() { $('#admin_form').append('<input type="hidden" name="'+$(this).attr('id')+'" value="'+$(this).html()+'"/>'); });It now works.