CKEditor does not save special characters

1

I'm using CKEditor version 4 and all good but the problem is that when I try to save a code block of the language that is for example: HTML, C #, JavaScript, Java, etc., it does not save it in the database , when I put words with accents or with ñ if you keep them.

My code is as follows:

<script>
function insert()
{
  var editorData = editor.getData();
  var contenido = editorData.replace(/&nbsp;/gi, ' ');

          $.ajax({
          type: "POST",
          url: "registrar.php",
          data: "contenido=" + contenido, 
          success: function(data)
          {
            alert("Registro  realizado");
          }         
          });
}
</script>

<form action="" method="post">
<textarea name="editor" id="editor" rows="10" cols="80">
</textarea>
<br>
<input type="button" value="Subir" name="boton" onClick="insert();">
<script>
var editor = CKEDITOR.replace('editor');
</script>
</form>

register.php

<?php
include_once("class.Database.php");

extract($_POST);
# contenido

$query = "INSERT INTO editor(contenido) VALUES('$contenido')";
Database::insert($query);
?>

I am using the config file of the CKEditor and I have it like that

CKEDITOR.editorConfig = function( config ) {

    // Simplify the dialog windows.
    config.removeDialogTabs = 'image:advanced;link:advanced';
    config.language = 'es-mx';
    config.entities = false;
    config.basicEntities = false;
    config.entities_greek = false; 
    config.entities_latin = false; 
    config.toolbarCanCollapse = true;
    config.extraPlugins = 'codesnippet';
    config.filebrowserUploadUrl = 'upload.php';
};

I used config.allowedContent = true; and nothing like I could solve this ??

I have been searching and I have noticed that the character & he does not read it because when he meets that character he does not say what is missing:

For example if I put: &lt; does not send anything but if I put lt;& send <p>lt;

Then I think the problem is that he can not read that character, I've tried other characters and he can read them.

I've already tried putting config.forceSimpleAmpersand = true; and config.forceSimpleAmpersand = false; and does not give a solution.

    
asked by Jorge Alonso 05.11.2018 в 19:16
source

1 answer

0

Well after searching since my question still has no answer, I found a solution, I realized that ckeditor if it takes any character well but ajax does not recognize the character & When sending to php, what I had to do was escape that character to avoid problems with ajax in the shipment. I leave my code in case someone has that same problem.

<script>
function insert()
{
  var editorData = editor.getData();
  var contenido = editorData.replace(/&nbsp;/gi, ' ');
  contenido = contenido.replace(/&/g, "%26");

          $.ajax({
          type: "POST",
          url: "registrar.php",
          data: "contenido=" + contenido, 
          success: function(data)
          {
            alert("Registro  realizado");
          }         
          });
}
</script>
    
answered by 06.11.2018 / 16:19
source