Idontreallywolf Idontreallywolf - 1 month ago 25
HTML Question

CKEditor — EMPTY VALUE (Jquery-Ajax Submit)

I created a website & added CKEditor.. I have a form with 3 normal input fields and then a textarea which is replaced by the CKEditor. But When i submit the form, value of CKEditor isn't showing up.

HTML:

<form id="pform" method="post">
<input class="poster_name" type="text" name="poster_name" placeholder="Namn">
<input class="title" type="text" name="title" placeholder="Titel">
<input class="subject" type="text" name="subject" placeholder="Ämne">
<textarea name="article" id="editor1"></textarea>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace('editor1');
</script>
<a class="submit_postform">Send</a>
</form>


JQUERY:

$('.submit_postform').click(function(){
$.ajax({
url:'pages/post.php',
type: 'POST',
data: $('#pform').serialize(),
success: function(data) {
alert(data);
$('.poster_name').val('');
$('.title').val('');
$('.subject').val('');
}
});
});

Answer

That's because the data from the CKEDITOR "moved" to the textarea only before submitting - so you won't see the content in the textarea using .val(). You can access CKEDITOR directly to get the data:

var editor = CKEDITOR.instances['DOM-ID-HERE'].getData();
Comments