Extending Kunena topic form with additional input items

Rate this item
(2 votes)

Kunena is very popular forum component for Joomla CMS. It has many fuctions and adjustments but possibility to add custom fields for new topics is still not a part of standard solution. Such request for adding this feature is high rated on Kunena site. One of possible solution how to do it in existing version of  Joomla 2.5 / Kunena 1.7 is described below.

 

When is important for specific topic category to force inclusion of some dedicated inputs as shown on the picture (Describe site) and these inputs have to be included into message after form submit then is necessary to change two files of Kunena component code.

We shall not change default template of Kunena to retain possibility for future upgrades and therefore we create custom template with simple copying entire default template under new name into template directory and renaming the template name in template.xml file :
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE install>
<kinstall type="kunena-template" version="1.6">
    <name>Blue Eagle JCMain</name>

Then we add in template/editor/bbcode.php to the code end following patch :

<?php
if (!$this->kunena_editmode && strlen(trim($this->message_text)) === 0) :
  ?>
  <tr class="krow<?php echo 1+$this->k; ?>">
    <td class="kcol-first kcol-editor-label"><strong>Describe site</strong><br/>(if applicable)</td>
    <td class="kcol-last kcol-editor-field">
      <div style="width: 200px;clear: both;float: left;">Joomla version</div>
      <div style="float: left;"><select name="addinfo-jver" id="addinfo-jver">
          <option>--</option>
          <option>2.5</option>
          <option>1.7</option>
          <option>1.6</option>
          <option>1.5</option>
        </select>
      </div>
      <div style="width: 200px;clear: both;float: left;margin-top: 10px;">JotCache version</div>
      <div style="float: left;margin-top: 10px;"><input name="addinfo-jotv" id="addinfo-jotv" type="text" size="50" value=""/></div>
      <div style="width: 200px;clear: both;float: left;margin-top: 10px;">site template</div>
      <div style="float: left;margin-top: 10px;"><input name="addinfo-tpl" id="addinfo-tpl" type="text" size="50" value=""/></div>
      <div style="width: 200px;clear: both;float: left;margin-top: 10px;">3rd parties system plugins</div>
      <div style="float: left;margin-top: 10px;width:100%;"><input name="addinfo-plgs" id="addinfo-plgs" type="text" value="" style="width:95%;"/></div>
    </td>
  </tr>
<?php endif; ?>

Now we shall see the added inputs for new topic form and reply form only.
Second part of solution is performed with page javascript. Joomla 2.5 is using MooTools Core 1.4.1 and More 1.4.0.1 with compatibility layer for 1.2. In template/js/editor.js file is necessary to include new code in function myValidate(f) :

function myValidate(f) {
  if (document.formvalidator.isValid(f)) {
    var jver = document.id('addinfo-jver').get('value');
    if(jver!='--'){
      var addinfo = "\n\n-----------------\nJoomla version  : "+jver+"\nJotCache version : "+document.id('addinfo-jotv').get('value')+"\nsite template: "+document.id('addinfo-tpl').get('value')+"\nsystem plugins  : "+document.id('addinfo-plgs').get('value');
      document.id('kbbcode-message').set('value', document.id('kbbcode-message').get('value') + addinfo);
    }
    return true;
  }
  return false;
}

After form submit is following text (depending on input of course) added to the message :

Read 3288 times Last modified onTuesday, 07 August 2012 07:36

Only registred users have rights to post comments. Please log-in or create an account.

We have 67 guests and no members online
Copyright © 2015 JotComponents
We have 67 guests and no members online
Copyright © 2017 JotComponents