Hi
i was wondering to hack the form of "add a blog entry" and add to it some TV input
so here is the tiny hack coming from various thread here for 0.9.6.1
in document.parser.class.inc (line 1800 )
// HACK **********************************************************
// Insert this about line 1800 in document.parser.class.inc.php
// right after function getTemplateVarOutput
// This one return an array of existing TV
function getTVListExist() {
$table = $this->getFullTableName("site_tmplvars");
$tvs = $this->db->select("name", $table);
// TODO: make it so that it only pulls those that apply to the current template
$dbfields = array();
while ($dbfield = $this->db->getRow($tvs))
{
$laTV=$dbfield['name'];
$tmp[$laTV]=TRUE;
}
return $tmp;
}
# Set template variable value
function setTV($tvname, $value, $docid="") {
if($tvname== "") return false;
if($docid == "") $docid = $this->documentIdentifier;
//get id of tv
$result=$this->db->select("id", $this->getFullTableName("site_tmplvars"), "name = '". $tvname . "'");
if (!$result) return false;
$row=$this->fetchRow($result);
// query the db to see if there are any records to update
$result=$this->db->select("Count(*) AS RecordsExist", $this->getFullTableName("site_tmplvar_contentvalues") , "tmplvarid=".$row['id']." AND contentid=".$docid);
$row2=$this->fetchRow($result);
if (!$row2['RecordsExist']) {
$fields = array(
"tmplvarid" => $row['id'],
"contentid" => $docid,
"value" => $value
);
$rows_affected = $this->db->insert($fields, $this->getFullTableName("site_tmplvar_contentvalues"));
} else {
$rows_affected = $this->db->update("value='" . $value . "'", $this->getFullTableName("site_tmplvar_contentvalues") , "tmplvarid=".$row['id']." AND contentid=".$docid);
}
return $rows_affected;
}
// END HACK **********************************************************
then duplicate the newsPublish snip to NewsPublisherHack
edit it and just after
// Doc group thing
// look in save_content.processor.php for tips (or below)
$lastInsertId = $modx->db->getInsertId();
add
//HACK INSERT THE TV'S IF EXIST
//Check each POST var and if a POST varname = TVname then insert the POST value by the way of setTV
$MaList=$modx->getTVListExist();
foreach ($_POST as $k => $v) {
if($MaList[$k]) $modx->setTV($k, mysql_escape_string($modx->stripTags($v)),$lastInsertId);
}
then in your formblog chunk youy can add something like
<label for="documentTags"><h4>Tags : </h4><input name="documentTags" id="documentTags" type="text" size="40" value="Tags here space separed" class="AddChamps"/></label>
and finally edit your "Add blog entry" document and change the call from NewsPublisher to NewsPublisherHack
done
But, it could be cool to have a way that in a public form we can call a [*TVNAME*] as a field and not a value
may be [*TVNAME:field*] that generate the correct field ?
PS: Im new modx user and i didn’t understand all for the moment , so, may this hack is not well coded ... I let moderateur correct it