Page 1 of 1

Saving to DB as parsed?

Posted: Fri May 29, 2009 11:47 pm
by sletts02
For some reason this is not saving any HTML codes, rather they are parsed and show in a browser. I.e.
It looks like this:
bold

Instead of:
bold

action.user_editcontent

Code: Select all

<?php

if (!isset($gCms)){
	exit;
}

$feusers = $this->GetModuleInstance('FrontEndUsers');
if( !$feusers )
{
	$this->_DisplayErrorPage( $id, $params, $returnid,
				  $this->Lang('error_nofeusersmodule'));
	return;
}

if(!$feusers->LoggedIn()){
	$this->Redirect($id, 'default', $returnid);
}

$cid = $params['cid'];

if (!isset($params['cid']))
{
	$this->_DisplayErrorPage( $id, $params, $returnid,
				  $this->Lang('error_nocid'));
	return;
}

$query = "SELECT * FROM ".cms_db_prefix()."module_simplewiki WHERE id=$cid";
$row = $db->GetRow($query);
//echo "Row (" . gettype($row) . "): " . $row . "  --  " . print_r($row);

$title = $row['title'];
$content = $row['content'];

$this->smarty->assign('img_path', 'modules/SimpleWiki/images/');
$this->smarty->assign('title_label', $this->Lang('title'));
$this->smarty->assign('content_label', $this->Lang('content'));
$this->smarty->assign('title', $this->CreateInputText($id, 'title', $title));
$this->smarty->assign('content', $this->CreateTextArea(true, $id, $content, 'content', '', 'textbox'));
$this->smarty->assign('cid', $this->CreateInputHidden($id, 'cid', $cid));
$this->smarty->assign('startform', $this->CreateFormStart($id, 'user_do_editcontent', $returnid,'post','multipart/form-data'));
$this->smarty->assign('endform', $this->CreateFormEnd());
$this->smarty->assign('submit', $this->CreateInputSubmit($id, 'submit', $this->Lang('submit')));
$this->smarty->assign('cancel', $this->CreateInputSubmit($id, 'cancel', $this->Lang('cancel')));


echo $this->ProcessTemplate('editor.tpl');


?>

action.user_do_editcontent

Code: Select all

<?php

if (!isset($gCms)){
	exit;
}

$feusers = $this->GetModuleInstance('FrontEndUsers');
if( !$feusers || !$feusers->LoggedIn()){
	$this->Redirect($id, 'default', $returnid);
}


if (isset($params['cancel']))
{
	$this->Redirect($id, 'default', $returnid, array('content_id'=>$cid));
}

$cid = $params['cid'];
$title = $params['title'];
$content = $params['content'];

$query = 'UPDATE '.cms_db_prefix().'module_simplewiki SET title=?, content=? WHERE id=?';

$dbr = $db->Execute($query, array($title, $content, $cid));

//$this->Redirect($id, 'default', $returnid, array('content_id'=>$cid));
$this->RedirectContent($returnid);


?>

Re: Saving to DB as parsed?

Posted: Sun May 31, 2009 3:11 am
by sletts02
Okay, I am pretty sure it has something to do with textboxes always stripping HTML when submitting from frontend.

Re: Saving to DB as parsed?

Posted: Sun May 31, 2009 3:40 am
by Jeff
Alot depends how it is entered. For example if it is a standard textarea it will be handled differently than if you typed it into TinyMCE editor.

Re: Saving to DB as parsed?

Posted: Sun May 31, 2009 7:56 am
by sletts02
Well I found a compromise that I am happy with :)

When outputting I just use htmlspecialchars_decode

Thanks for looking :)