I am working on preview feature of editting page in ckeditor. After any changes in field I am POSTing body to preview action and then saving it to session. After that I fetch data using GET. Unfortunatelly the body I have post is returned without any html tags so I can't preview images:[
Here's an previewAction:
public function previewAction() {
if($_POST) {
$id = rand(1, 100000);
unset($_SESSION['preview']);
if(isset($_POST['body'])) {
$_SESSION['preview'][$id] = array( 'body'=> $_POST['body'] );
echo $id;
exit;
}
else {
throw new Exception('Body not posted for preview');
}
}
elseif($this->params['param1']) {
$id = $this->params['param1'];
$page = new page();
$page->populate($_SESSION['preview'][$id]);
$this->view->page = $page;
$this->contentRender = 'index/page.php';
$this->render = 'content_only.php';
}
else {
exit;
}
And js function handling preview:
function updateSubmit(force) {
if(timeout_id)
clearTimeout(timeout_id);
if(cke && ( (busy==false && update_needed == true) || force==true ) ) {
timeout_id = setTimeout(function() {
if(busy==false) {
$.ajax({
type: 'POST',
url: '/index/preview/',
data: {body: cke.getData()},
success: function(data) {
$.each(iframe, function() {
$(this).attr('src', '/index/preview/'+data);
});
busy = false;
update_needed = false;
}
}
)
}
}
, 200);
}
}
Thanks in advance for help.
Check if the cke.getData()
function dont strip out the tags.
Or in PHP somewhere before this script you don't have strip_tags() or sth.
I feel like you are doing it wrong. Do not fetch the data using GET, just create hidden field if you need.
I don't think you need a SESSION here.
cke.getData() does not strip tags out. Session is not necesery in this script, however it's not an issue. Html is without tags after readig from $_POST['body'].