1

I've created a custom field for a module which gets some information from the database. I need to add the functionality to update the information in database if I make some changes.

Here is the code for my custom field which currently only gets the data from the database:

<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

jimport('joomla.form.formfield');
jimport('joomla.filesystem.file');
$app        = JFactory::getApplication();
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');

class JFormFieldAddlinks extends JFormField {

    protected $type = 'Addlinks';

    // getLabel() left out

    protected function getInput() {
        $html = '';
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select($db->quoteName(array('id', 'link_id', 'image', 'link')));
        $query->from($db->quoteName('#__links'));

        // Reset the query using our newly populated query object.
        $db->setQuery($query);
        $row = $db->loadRowList();

        foreach ($row as $key) {
            $html .= "<div class='group' style='clear:both;'>";
            $html .= "<input type='text' name='link' value='$key[2]'>";
            $html .= "<input type='text' name='image' value='$key[3]'>";
            $html .= "</div>";
        }

        return $html;
    }

    public function getLabel() {

    }
}

XML file:

<config>
    <fields name="params"> 
        <fieldset name="addlinks" label="Add Link" addfieldpath="/modules/mod_links/elements">
            <field type="addlinks" name="link"></field>
        </fieldset>
    </fields>
</config>
  • Does this module works only in the backend? Or you want to update information from the frontend? – Dmitry Rekun Jan 30 '15 at 7:07
  • this module works only on backend, but now problem solved, thx for feedback – Bob Dylan Feb 1 '15 at 13:58
  • 3
    Please post your answer to close the question. – Nils Rückmann Feb 23 '15 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.