custom inline editing for repeat region recordset
Hi, I want to adapt some code that Ray helped me with a while back which allows for inline editing...To explain how I am trying to adapt it...I have a latest news page on a website,,,so each record contains; news title, date posted and the main content. When admin is logged in on the news page there will be an "Edit" button for each news segment so this will then take the admin user to an edit page where the news title, news date and news content is displayed...then the admin user can edit (using inline editing) either the title or the main content (date doesnt need to be changed)....I got it working to some degree, however when I test and try to edit either the title or main content on update it will change both the title and the content to the same data!..
Here is the code I am using:
<div class="content-full">
<h4 style="float:left" contenteditable="true"><?php echo $row_rsNews['NewsTitle']; ?></h4>
<h5 style="float:right"><strong><?php echo $row_rsNews['NewsDate']; ?></strong></h5>
<p> </p>
<p> </p>
<div contenteditable="true"><?php echo $row_rsNews['NewsContent']; ?></div>
</div>
<script src="../js/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
if (window.CKEDITOR) {
CKEDITOR.on("instanceCreated", function (event) {
var editor = event.editor
var element = editor.element;
var titletext = element.getAttribute("h4");
var bodytext = element.getAttribute("div");
var toolbar = element.getAttribute("toolbar");
if ( element.is( 'h1', 'h2', 'h3', 'h4' ) || element.getAttribute( 'id' ) == 'taglist' ) {
editor.config.toolbar = [
["Bold","Italic","Underline","Strike", "Link"]
];
}
editor.on("blur", function() {
if (this.checkDirty()) {
if (confirm("Save Changes?")) {
this.resetDirty();
var params = {
ContentID: <?php echo $row_rsNews['NewsID']; ?>,
title_text: this.getData(titletext),
body_text: this.getData(bodytext)
};
$.ajax({
url: 'cms-update.php',
global: false,
type: "POST",
dataType: "text json",
data: params
});
} else {
element.innerHTML = this.oldEditorData;
}
}
});
editor.on("focus", function() {
this.resetDirty();
this.oldEditorData = this.getData(titletext);
this.oldEditorData = this.getData(bodytext);
});
});
}
</script>
Thi is the seperate update file:
<?php require_once('../Connections/medcalfdb.php'); ?>
<?php require_once("../webassist/database_management/wa_appbuilder_php.php"); ?>
<?php
// WA DataAssist Update
if ("" == "") // Trigger
{
$WA_connection = $medcalfdb;
$WA_table = "news";
$WA_redirectURL = "";
if (function_exists("rel2abs")) $WA_redirectURL = $WA_redirectURL?rel2abs($WA_redirectURL,dirname(__FILE__)):"";
$WA_keepQueryString = false;
$WA_indexField = "NewsID";
$WA_fieldNamesStr = "NewsTitle|NewsContent";
$WA_fieldValuesStr = "".$_POST['title_text'] ."" . $WA_AB_Split . "".$_POST['body_text'] ."";
$WA_columnTypesStr = "',none,''|',none,''";
$WA_comparisonStr = "=|=";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode($WA_AB_Split, $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_where_fieldValuesStr = "".($_POST["ContentID"]) ."";
$WA_where_columnTypesStr = "none,none,NULL";
$WA_where_comparisonStr = "=";
$WA_where_fieldNames = explode("|", $WA_indexField);
$WA_where_fieldValues = explode($WA_AB_Split, $WA_where_fieldValuesStr);
$WA_where_columns = explode("|", $WA_where_columnTypesStr);
$WA_where_comparisons = explode("|", $WA_where_comparisonStr);
$WA_connectionDB = $database_medcalfdb;
mysql_select_db($WA_connectionDB, $WA_connection);
@session_start();
$updateParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WhereObj = WA_AB_generateWhereClause($WA_where_fieldNames, $WA_where_columns, $WA_where_fieldValues, $WA_where_comparisons );
$WA_Sql = "UPDATE `" . $WA_table . "` SET " . $updateParamsObj->WA_setValues . " WHERE " . $WhereObj->sqlWhereClause . "";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
Regards
Chris
Actually I understand that referencing the H4 and DIV tags wouldnt work since there could be many on a page...but the original code used REL="" inside the H4 and DIV tags however since the REL attribute was used in the javascript I cannot figure out how to reference it twice. Since the original code in the javascript would be something like: var titletext = element.getAttribute("rel");
What I was thinking is, in the javascript code I used an IF condition, so for example:
<h4 style="float:left" contenteditable="true" rel="newstitle"><?php echo $row_rsNews['NewsTitle']; ?></h4>
<h5 style="float:right" rel="newscontent"><strong"><?php echo $row_rsNews['NewsContent']; ?></strong></h5>
<script type="text/javascript">
if (window.CKEDITOR) {
CKEDITOR.on("instanceCreated", function (event) {
var editor = event.editor
var element = editor.element;
var titletext = element.getAttribute("rel");
var bodytext = element.getAttribute("rel");
.....some IF statement to check if rel=newstitle
if it does then do something here
.....some IF statement to check if rel=newscontent
if it does do something here