I am using tinymce for posting data in CodeIgniter, but am not able to get the data from the tinymce editor for some instance am able to get the data and store it in the database but most of the times am unable to get the data. Am providing the jquery code and ckeditor script which I have used please let me know how I can get the data
$content = strip_tags(trim($this->db->escape_str($this->input->post('content'), " ")));
<script type="text/javascript">
$(document).ready(function () {
if($("#content").length > 0){
tinymce.init({
selector: "textarea#content",
theme: "modern",
height:300,
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste textcolor"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l ink image | print preview media fullpage | forecolor backcolor emoticons",
style_formats: [
{title: 'Bold text', inline: 'b'},
{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
{title: 'Example 1', inline: 'span', classes: 'example1'},
{title: 'Example 2', inline: 'span', classes: 'example2'},
{title: 'Table styles'},
{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
]
});
}
});
</script>
<script>
$(function() {
$('#edit_article').validate({
rules: {
"title": {
required: true
},
"content":{
required: true
},
"metatitle":{
required: true
},
"metadesc":{
required: true
},
"metakey":{
required: true
},
"metah1":{
required: true
},
"metaimage":{
required: true
},
"seourl":{
required: true
}
},
messages: {
"title": {
required: "Please Enter Title"
},
"content": {
required: "Please Enter Content"
},
"metatitle": {
required: "Please Enter Meta Title"
},
"metadesc": {
required: "Please Enter Meta Description"
},
"metakey": {
required: "Please Enter Meta Keywords"
},
"metah1": {
required: "Please Enter Meta H1 Tag"
},
"metaimage": {
required: "Please Enter Meta Image Title"
},
"seourl": {
required: "Please Enter SEO Url"
}
},
submitHandler: function(form) {
var myForm = document.getElementById('edit_article');
$.ajax({
type: 'post',
url: '<?php echo base_url(); ?>admin/edit_article/<?php echo $article_data[0]->ARTICLEID; ?>',
dataType: 'text', // what to expect back from the PHP script, if anything
cache: false,
contentType: false,
processData: false,
data: new FormData(myForm),
// data: $('#edit_article').serialize(),
success: function(data) {
// alert(data);
var yourval = jQuery.parseJSON(JSON.stringify(data));
var obj = jQuery.parseJSON(data);
// alert(obj);
if (obj.status == 1) {
swal("Good job!", obj.message, "success").then(function(){
window.location.reload();
});
// $('#edit_video')[0].reset();
} else {
swal({
type: 'error',
title: 'Oops...',
text: obj.message
})
}
}
});
return false;
}
});
});
</script>
You have two options:
Save tinymce content to its original textarea before the ajax call like this:
tinyMCE.triggerSave(true,true);
Append the content to your formdata:
var formdata = new FormData(myForm);
formdata.append("textarea", tinyMCE.getContent('content'));