I’m using ckeditor in a textarea:
The code for the form:
<form id="form" name="myform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea name="content" >
<?php echo $_POST['content']; ?>
</textarea>
The form will be send to the current page, here is the code to insert the code into the database:
if(isset($_POST['submit']))
{
if (empty ($_POST['naam']) or empty($_POST['content']) or empty($_POST['omschrijving']) or empty($_POST['auteur']) or empty($_POST['keywords']))
{
echo '<h1>TEST</h1>';
echo '<script type="text/javascript">
alert("Er zijn velden die niet ingevuld zijn. Deze zijn met rood gemarkeerd");
</script>';
}
else
{
echo 'nog niet verwerkt';
//alles is ingevuld
$sql = "INSERT INTO sitecontent (ID, postnaam, post_inhoud, pagina, publiceren)
VALUES ( '" . $_POST['id'] . "', '" .mysql_real_escape_string($_POST[naam]) ."', '" .mysql_real_escape_string($_POST[content]) . "' , '" .mysql_real_escape_string($_POST[pagina]). "' , '" . $_POST['publiceren']. "' )";
$query = $con->exec($sql);
echo 'verwerkt';
}
}
(I’m using PDO PHP 🙂 ) There are some echo’s for debugging my code.
Here is the code to change the textarea to a ckeditor:
<script type="text/javascript">
CKEDITOR.replace('content');
</script>
New my question ofcourse. If I post the content in the textarea, it will be insert into the database. And the inserted content will be displayed in the textarea.
I have an autosave function, the code is from stackoverflow. And it works fine. But if i change the value of textarea, it will only insert the code between the textarea tags.
So my problem is: my code will only insert the content from the textarea between the textarea tags.
I hope my question is clear. I can post the autosave code, but that works perfect for other input fields on the form. And it is the same code for inserting as above.
Sorry for my bad English, I hope you can understand me.
Thanks!
Before you can submit the form, you need to tell CKEditor to save its contents back into the text area:
Then run
CKupdate()before you save the form. See also: https://stackoverflow.com/a/3256553/1338292