skip to Main Content

I have this form for a blog.
It works well with ajax no refresh, just serialize and submit data.
Then i decided using ckeditor 5 the value of the textarea isnt submitted.

my ajax script

$(document).ready(function(){
    $("#create").click(function(event) {
        event.preventDefault();

        var form = $("#mytest");
        var formData = new FormData($("#mytest")[0]);
        $.ajax({
          url  : "test3.php",
          type : "POST",
          cache: false,
          contentType : false,
          processData: false,
          data: formData,
          success:function(response){
            $(".test").html(response);
          }
        });
    });
});

my html form

<form id="mytest" action="">
    <input type="number" name="number" value="">
    <br>
    <textarea class="editor" name="textarea"></textarea>
    <input type="submit" id="create" value="submit content">
</form>

<p class="test"></p>

my php code

$textarea = $_POST["textarea"];
$number = $_POST["number"];

echo $textarea;
echo $number;

2

Answers


  1. Chosen as BEST ANSWER

    Give the textarea an id of mycontent.

            $(document).ready(function(){
                $("#create").click(function(event) {
                    event.preventDefault();
    
                    $('#myContent').val($('.ck-content p').text());
    
                    var form = $("#mytest");
                    var formData = new FormData($("#mytest")[0]);
                    $.ajax({
                      url  : "test3.php",
                      type : "POST",
                      cache: false,
                      contentType : false,
                      processData: false,
                      data: formData,
                      success:function(response){
                        $(".test").html(response);
                      }
                    });
                });
            });
    

    Thats the way i did it...


  2. CKEditor wraps textarea in its own html markup, so in order to get that textarea text try:

    $('.ck-content p').text();
    

    In one of the earlier CKEditor versions I do

    $('iframe').content().find('body').text();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search