简体   繁体   中英

Use CKEditor with CKfinder and save content to the database

I have a textarea which is a Ckeditor however I included the ckfinder which allows me upload images. I need to send all the data inside the textarea to a page to process the data received.

Actually I can't send the data which is inside of the textarea.

      <label>Corpo da Instrução de Trabalho</label>
      <textarea name="editor1" id="editor1" rows="10" cols="80" placeholder="Escrever o conteúdo da IT aqui...">

      </textarea>

      <script>

      // Replace the <textarea id="editor1"> with a CKEditor
      // instance, using default configuration.

     // CKEDITOR.replace( 'editor1' );

     var editor = CKEDITOR.replace( 'editor1' );
     CKFinder.setupCKEditor( editor );

   </script>

When I try to save the data on the file which receive the data I do something like this:

$myText = $_POST['editor1'];

But it's empty.

You need to submit it along with a form. And to include ckeditor.js file in the head tag: example:

index.php

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="robots" content="noindex, nofollow">
    <title>Classic editor replacing a textarea</title>
    <script src="http://cdn.ckeditor.com/4.6.2/standard-all/ckeditor.js"></script>
</head>

<body>
    <form action="savetextarea.php" method="post" >

    <textarea cols="80" id="editor1" name="editor1" rows="10">
    </textarea>

        <p>
            <input type="submit" value="Submit">
        </p>
    </form>

    <script>
        // CKEDITOR.replace( 'editor1' );
    var editor = CKEDITOR.replace( 'editor1' );
    CKFinder.setupCKEditor( editor );
    </script>
</body>

</html>

create savetextarea.php in the same folder and don't forget to print out the content:

<?php

$my_text = $_POST['editor1'];
print_r($my_text);

When you refresh the page add some image from example :-) and add some text, when you submit it it will show the content on your savetextarea.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM