Fairly new to Joomla development. Put a folder called Forms in model folder to load the necessary JForm data. Everything is working fine but I need to grab data dynamically from the database to populate a drop down box.
<field name="category"
type="list"
label="Item Category"
description="Item Category"
class="inputbox"
>
<option value="1">
Data from database</option>
<option value="2">
Data from database</option>
<option value="3">
Data from database</option>
</field>
The above is a rough example. I want the values and option names to come from a database. Do I use a JTable or params and if so how? I much appreciate any help. Thanking you all.
You can do that by creating your own field type. Joomla Com_Categories have that field type (administrator/com_categories/models/fields/categoryedit.php) to populate drop down with categories using categoryedit as field type in category.xml for dropdown html element.
<field
name="parent_id"
type="categoryedit"
label="COM_CATEGORIES_FIELD_PARENT_LABEL"
description="COM_CATEGORIES_FIELD_PARENT_DESC"/>
You can use "sql" type for dynamic data-
http://docs.joomla.org/SQL_form_field_type
like below example-
<field
name="link"
type="sql"
default=""
class="articleselectbox"
label="Select an article"
query="SELECT
concat(#__categories.alias, '/', #__content.id,'-', #__content.alias,'.html') as value,
concat(#__categories.alias, '/', #__content.id,'-', #__content.alias,'.html') as title
FROM #__content
LEFT JOIN #__categories ON #__content.catid=#__categories.id
ORDER BY #__content.title"
key_field="title"
value_field="value"
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With