Reputation: 117
I'm building a editable website for some people, I'm using ckeditor to let them be able to use WYSIWYG online, but when I'm using a post method to save the data, the code get messed up...
This is how I use ckeditor to save the tabs and all of my editable website:
<html>
<head>
<title>CKEditor Sample</title>
<script src="ckeditor/ckeditor.js"></script>
</head>
<body>
<form action="login/updateText.php" method="post">
<p>
File being modified: <textarea name="name" id="name">about.php</textarea>
<textarea name="editor1" id="editor1">
<?php echo file_get_contents('about.php');?>
</textarea>
<script>
CKEDITOR.replace( 'editor1' );
</script>
</p>
<p>
<input type="submit">
</p>
</form>
</body>
</html>
but after editing this:
<div class="menuslct">
<table border="0" style="text-align:center; width:980px">
<tbody>
<tr>
<td><a href="/en/aboutus"><img src="/common/img/icons/aboutus.png" style="height:80px; width:80px" /></a></td>
<td><a href="/en/aboutus/ourteam"><img src="/common/img/icons/12 our team.jpg" style="height:78px; width:78px" /></a></td>
<td><a href="/en/aboutus/howtohelp"><img src="/common/img/icons/11 help.jpg" style="height:78px; width:78px" /></a></td>
</tr>
<tr>
<td>About Us</td>
<td>Our Team</td>
<td>How to help</td>
</tr>
</tbody>
</table>
</div>
the saved html code looks like this:
<div class="\"menuslct\"">
<table border="\"0\"" style="\"height:80px">
<tbody>
<tr>
<td>About Us</td>
<td>Our Team</td>
<td>How to help</td>
</tr>
</tbody>
</table>
</div>
<p><a href="\"><img src="\" style="\"height:78px" /></a><a href="\"> <img src="\" style="\"height:78px" /></a></p>
and here is updateText.php:
<?php
$filename = $_POST['name'];
$str = $_POST['editor1'];
$fh = fopen($filename, "w");
fwrite($fh, $str);
fclose($fh);
header("Location: modify.php");
?>
So I have no idea as to what I'm messing up...
Upvotes: 0
Views: 558
Reputation: 12665
It looks like magic quotes messes up your $_POST vars.
Disable it in your php.ini file:
; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off
Upvotes: 1
Reputation: 588
If you want to add HTML code with CKEditor you must first make sure that you have pressed the "Source" button first otherwise it is going to encode the inputs and you will get the issue above.
Upvotes: 0