I am using CKEditor version 4 and everything is fine but the problem is that when I try to save a block of language code 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 save them.
My code is the following:
<script>
function insert()
{
var editorData = editor.getData();
var contenido = editorData.replace(/ /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 CKEditor config file and I have it like this
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 have used config.allowedContent = true;
and nothing how could I solve this??
I have been searching and I have realized that the character & does not read it since when it finds that character it does not put the missing:
For example if I put:
<
it does not send anything but if I put it lt;&
sends<p>lt;
So I think the problem is that it can't read that character, I've tried other characters and it can read them.
I have already tried putting config.forceSimpleAmpersand = true;
y config.forceSimpleAmpersand = false;
and it does not give a solution.
Well after searching since my question still does not get an answer, I have found a solution, I realized that ckeditor does take 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 on submission. I leave my code in case someone has the same problem.