I was struggling with the front end submission of an article. I have set up multiple categories in the News (version 2.11 with Core 1.9.2). Some of the categories have sub categories. One of the parent categories is called Review and has subcategories. The 'problem' I was facing was that I wanted to use front end entry of articles, but only allow the visitor/user to select from the sub categories of parent category Review.
As a programmer I thought of changing the code of action.fesubmit.php in the news module. However that is not upgrade friendly. I used in stead a combination of the smarty and a UDT.
In the front end template of news, you will find the following for the category selection:
Code: Select all
<div class="pageoverflow">
<p class="pagetext">{$categorytext}:</p>
<p class="pageinput">{$inputcategory}</p>
</div>
Code: Select all
// The list of categories build in this UDT will be used in the front end submit of reviews, to only allow
// selection of module names. This leaves room to have news about the site or news coming from
// external sources to be booked in a different category
// UDT RebuildInputCategory by Duketown 2011
$inputcategory = $params['inputcategory'];
$parentno = $params['parentno'];
// Intercept the inputcategory given by the News module.
// It also contains the return id and security id. By substringing it, we don't have to worry about that
// You might have to alter the total length of 57
$inputctg = substr($inputcategory, 0, 57);
// Build the category list
$db = cmsms()->GetDb();
$query = "SELECT * FROM ".cms_db_prefix()."module_news_categories
WHERE parent_id = ?";
$dbresult = $db->Execute($query, array($parentno));
// Read all the categories and form options from each of them
while ($dbresult && $row = $dbresult->FetchRow()) {
$inputctg .= '<option value="' . $row['news_category_id'] . '">';
$inputctg .= $row['news_category_name'];
$inputctg .= '</option>';
}
$inputctg .= '</select>';
return $inputctg;
Notice that the last line of the UDT contains the variable with the option set and that it is given back to the calling part.
Now that the UDT is prepared, go back to the form template. We have to change the {$inputcategory} into the following:
Code: Select all
{RebuildInputCategory inputcategory=$inputcategory parentno="2"}
The first being the variable passed from the News module and the second being the parent number as found during editing the parent category.
The parentno parameter will sure have something else in your situation.
Happy UDT-ing,
Duketown
