Hi,
I would like to be able to fill the values for a dropdown select with values froma database. Is this possible?
public function getOptions()
{
$alias=$this->element['name'];
if($alias=='alias_of_field') // set the alias of your field (width this conditions the select type work normally for all field except for this field)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id AS value, a.title AS text') // set db column for value and text (in this example id => value and title => text)
->from('#__content AS a'); // set db table (in this example the table is #__content , this table contains all articles of your site)
->where('state="1"'); // set where where of query (in this example we filter only published aticles)
$db->setQuery($query);
try
{
$options = $db->loadObjectList();
}
catch (RuntimeException $e)
{
return false;
}
$options = array_merge(parent::getOptions(), $options); // Merge any additional options in the fields params (you can remove this).
return $options;
}
else
{
return parent::getOptions();
}
}