Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Max Gano on Jun 13, 2009 21:37
open dhtmlx forum
dhtmlxAjax seems to be truncating HTML string being sent to database

Hi, again. Really hope you can help with this one.

I am using dhtmlxEditor to allow users to edit page content in layout cells. I am storing the resulting content in MySQL text field through the use of dhtmlxAjax method.

My issue is that the content, once edited and saved to the database, is being truncated with no obvious pattern other than it always seems to occur most predictably after it has been saved to the database the first time and is subsequently edited again. There is no obvious edge determining the length at which the truncation occurs.

I suspect this occuring in the Ajax getSync call that I am using to send the content to the database through a PHP connector I created for that purpose.

I am not sure which javascript is providing the ajax method, but dhtmlxCommon.js we are using is v.2.1 build 90226

Here is the function block I am using to invoke the editor:

-------------------- begin code sample --------------------

function constructSplashScreen(_bldSplash) {
if (editMode) {
workZoneLayout.cells("a").collapse();
workZoneLayout.cells("c").collapse();
clearToolbars();
workZoneLayout.cells("b").layout = null;

var myEditor = workZoneLayout.cells("b").attachEditor();
myEditor.setIconsPath("codebase/dhtmlx/imgs/");
myEditor.init();
myEditor.tb.addSeparator("save_sep1",0);
myEditor.tb.addButton("save_edits", 1, "SAVE");
myEditor.tb.addSeparator("save_sep2",2);
myEditor.setContentHTML("api/items/generic/content_generic.php?it=" + _bldSplash);
myEditor.tb.attachEvent("onClick", function(id){
if (id == 'save_edits') {
var _str = myEditor.getContent();
alert(_str);
var loader = dhtmlxAjax.getSync("api/items/generic/content_generic_save.php?it=" + _bldSplash +"&content_str=" + _str);
alert("api/items/generic/content_generic_save.php | it=" + _bldSplash +"&content_str=test");
alert('Changes Saved');
}
});
}
else {
workZoneLayout.cells("a").collapse();
workZoneLayout.cells("c").collapse();
clearToolbars();
workZoneLayout.cells("b").layout = null;
// TODO: hide all paths by loading from an ini file into js variable
workZoneLayout.cells("b").attachURL("api/items/generic/content_generic.php?it=" + _bldSplash);
}
}

-------------------- end code sample --------------------

the code for the connector is:

-------------------- begin code sample --------------------

<?php
include '../../../conf/db_conf.php';
require_once 'DB.php';
$dsn = array
(
'phptype' => 'mysql',
'username' => $dbuser,
'password' => $dbpwd,
'hostspec' => $dbhost,
'database' => $dbname
);

$options = array('debug'=> 2,);

$db = DB::connect($dsn);
if (DB::isError($db)) {echo 'connect failed'; die($db->getMessage());}

$item_type ='';
if (isset($_GET['it']) && $_GET['it'] != "") {$item_type = $_GET['it'];}

$content_str = '';
if (isset($_GET['content_str']) && $_GET['content_str'] != "") {$content_str = $_GET['content_str'];}

$sql = 'select blurb from content where type = "' . $item_type . '"';
$res = $db->query($sql);

if (DB::isError($res)){die($res->getMessage());}

if ($res->numRows() > 0) {
$sql = 'update content set blurb = ? where type = ?';
$params = array($content_str,$item_type);

$query = $db->prepare($sql);
if (DB::isError($query)) {echo 'query preparation failed'; die($query->getMessage());}

$res = $db->execute($query, $params);
if (DB::isError($res)) {echo 'query execution failed'; die($res->getMessage());}
} else {
$sql = 'insert into content (blurb,type) values (?,?)';
$params = array($content_str,$item_type);

$query = $db->prepare($sql);
if (DB::isError($query)) {echo 'query preparation failed'; die($query->getMessage());}

$res = $db->execute($query, $params);
if (DB::isError($res)) {echo 'query execution failed'; die($res->getMessage());}
}
?>

-------------------- end code sample --------------------





Here is a string of html that was stored to the database the first time prior to editing.

-------------------- begin content sample --------------------

<H4>Cost-Effective and To The Point</H4><P>Designed specifically for community banks and credit unions, simple, step-by-step guides allow customers to quickly get up and running. OONdada is simply the most cost effective solution available. </P><P><STRONG>Summarize for Executives</STRONG></P><UL><LI>Clearly align compliance and audit priorities to business policy</LI><LI>Define common goals and objectives consistent with product roadmaps </LI><LI>View summaries of all activities planned or currently underway</LI><LI>Prevent confusion from derailing your first</LI></UL><P><STRONG>Focus on Compliance</STRONG></P><UL><LI>Coordinate responses to changing landscape of requlations and other market conditions </LI><LI>Establish a common view of your business, its processes and systems </LI><LI>Deploy controls, show where they will be established and track assignment of responsibility</LI><LI>Leverage common views of the business processes and systems to identify where to conduct audits </LI></UL><P><STRONG>Audit Focus</STRONG></P><UL><LI>Eliminate spreadsheet management hassles through central assessment entry </LI><LI>Identify and track areas of particular risk for audit prioritization and planning </LI><LI>Archive your work to ensure that audit responses are safely and accurately preserved </LI></UL><P></P>

-------------------- end content sample --------------------





And, finally, here is a truncated version of that same html string following edits

-------------------- begin content sample --------------------

<H4>Cost-Effective and To The Point</H4><P>Designed specifically for

-------------------- end content sample --------------------
Answer posted by Alex (support) on Jun 15, 2009 01:10

Hello,

please, use the POST method to send data. As the GET method is only allowed a limited amount of data . 

Also you can escape _str parameter: encodeURIComponent(_str) instead of _str.