I want at the fieldset of a joomla module to echo an option with some fetched results from my db:

<fields name="params">
<fieldset name="basic">

$db =& JFactory::getDBO();
$query = $db->getQuery(true);

$options = $db->loadObjectList();
echo "<select>";
echo "<option value=''>select a category</option>";
foreach($options as $row) { 

   echo "<option value='" . $row->id ."'>" . $row->title . "</option>";

   echo "</select>";

I know that this code is completly wrong (just posted it to show you what I want to do ), but I allready searched for modules that do something similar and I found out, that they don't use php code inside xml.

So I guess there is another way, but I can't understand on my own, as I am completely new to Joomla and Joomla development.

Thanks in Advance.

2 Answers 2


Try this ,

Normally Joomla provides all major components categories in XML accessible way.

For eg: you need banner category dropdown simply use like below.

                    multiple="true" size="5"
                    description="Your desc" >
                    <option value="">JOPTION_ALL_CATEGORIES</option>

For content categories you can try something like com_content instead of com_banners. check for your menu too, Im not sure if that available or not.

If it is not there also Joomla offer another option of writing SQL in XML files.

something like below.

<field name="myfield" type="sql" default="10" label="Select an article" query="SELECT id, title FROM #__content" key_field="id" value_field="title" required="true">
<option value="">Please select your option</option>

more details can be found here.

Hope it helps.

  • For more xml fields can be found here
    – Jobin
    Nov 6, 2014 at 11:18
  • 1
    That was really helpful,Im sure that i wont find something that fits me from components list because in my module i want to fetch all: menus,submenus,virtuemart categories, and much more so i guess writing a query will be better.
    – IseNgaRt
    Nov 6, 2014 at 11:31

I would suggest taking a look at http://docs.joomla.org/Creating_a_custom_form_field_type Since it looks like what you are trying to achieve. While the guide may be referring to components this can also work with modules, (I've tried it myself)

simply follow the guide but instead of placing your files at

/administrator/components/<name of your component>/models/fields/<name of your field>.php

You should place them at

/modules/<name of your module>/models/fields/<name of your field>.php


See http://docs.joomla.org/Selecting_data_using_JDatabase for ways to fetch data from the Joomla Database, use this in the code you have learned from the previous link

  • Ok i did the steps and i echoed a select with 3 options like the example, but its completly different to return a select with fetched values from the database. Im still trying to figure out how to do that
    – IseNgaRt
    Nov 6, 2014 at 11:01
  • Updated my answer to fit your needs better :)
    – Rasmus Boie
    Nov 6, 2014 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.