Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE not sending value

Hi All
It's the first time I've used Tiny Mce and I have a problem. Please Help

The editor works fine in editing but when I click submit nothing is sent from the textarea input

Here is the code:

<textarea name='proddesc' class='text_area' id='elm1' /></textarea>

I'm using jQuery, this is the code:

$('#addprod').submit(function(){
                $("#addprodmsg").hide();
        $.post('addprod.php', $("#addprod").serialize(), 
            function(data){
                    $("#addprodmsg").html(data);
        });
                $("#addprodmsg").show();
                return false;
});

The Php Code is:

foreach($_POST as $key){echo "<script>alert('$key')</script>";}

Everything alerts a value but the textarea is not alerting anything.

Also, when I disabled TinyMce and submit the form everything is ok.

2 - I'm using the rtl direction and I have this photo:

http://www.image-upload.net/images/mly8a68ufs0mdeky6low.jpg

Look At Style :(

Thank You

like image 322
SamarLover Avatar asked Apr 27 '11 16:04

SamarLover


People also ask

How do I get TinyMCE editor value?

The TinyMCE getContent and setContent methods You can do this using the getContent() API method. Let's say you have initialized the editor on a textarea with id=”myTextarea”. This will return the content in the editor marked up as HTML.

How do I know if my TinyMCE is empty?

You can do this to check if the content is empty without parsing html: var content = tinymce. get('tinymceEditor'). getContent({format: 'text'}); if($.

How do I reinitialize TinyMCE?

Use tinymce. remove() method to remove TinyMCE editor from the HTML element and again call tinymce. init() on the selector to reinitialize.

How do I get the content of TinyMCE editor in jQuery?

You can use the activeEditor for that, or if (for some reason) you have the original element that created the editor in a jQuery object, you can use that jQuery object to get the id of the original element and use that in order to get the content of the TinyMCE (using the TinyMCE editor).


2 Answers

It is necessary to update the textareas content with the content of the editors iframe (tinymce uses an editable iframe like most rtes). In order to achieve this you need to call tinymce.get('elm1').save(); before you submit.

You can also grab the editors content using tinymce.get('elm1').getContent(); and sent this.t

like image 117
Thariama Avatar answered Sep 28 '22 09:09

Thariama


Why TinyMCE is not sending updated value?
Tinymce will not update the html/content of hidden textarea input field when you are using ajax to submit a form. You need to update the content/html of textarea input field manually before submit a form using tinyMCE.triggerSave(). Note: textarea will be hidden when you will use it as Tinymce.

How TinyMCE will send updated value?
Now we will push the content/html of TinyMCE to textarea.

$("form").submit(function (event) {
        event.preventDefault();
        tinyMCE.triggerSave(); //this line of code will use to update textarea content
        
        //your ajax function/code
});
like image 29
dev Avatar answered Sep 28 '22 11:09

dev