Support

Akeeba Ticket System

#20519 Suggestion: Auto-populate a list from a table -> Dropdowns etc..

Posted in ‘Akeeba Ticket System for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Akeeba Ticket System version
n/a

Latest post by tampe125 on Thursday, 17 July 2014 10:36 CDT

user84964
 Hi,

I would like to auto populate the options in custom fields from existing tables.

Example: Product Listings in a Dropdown

If you have a lot of products it could be a real pain to define all options in the options fields.

There is also a good chance that products will differ from time to time and you have to do the changes manually.


For exaple, RSForms is using following code to auto-populate lists

// Prepare the empty array
$items = array();
// Prepare the database connection
$db = JFactory::getDbo();
// Keep this if you'd like a "Please select" option, otherwise comment or remove it
$items[] = "|Please Select[c]";
 
// Run the SQL query and store it in $results
$db->setQuery("SELECT your_value, your_label FROM #__your_table");
$results = $db->loadObjectList();
 
// Now, we need to convert the results into a readable RSForm! Pro format.
// The Items field will accept values in this format:
// value-to-be-stored|value-to-be-shown
// Eg. m|M-sized T-shirt
foreach ($results as $result) {
  $value = $result->your_value;
  $label = $result->your_label;
  $items[] = $value.'|'.$label;
}
 
// Multiple values are separated by new lines, so we need to do this now
$items = implode("\n", $items);
 
// Now we need to return the value to the field
return $items;


Is this also possible with ATS ?

cheers
Alexandra

tampe125
Akeeba Staff
Hello Alexandra,

there isn't any built-in support for dynamic fields and sql queries.
The main reason is that such feature could led to security issues (what if you query the wrong table and fetch the wrong fields?).

If you want to create a new field populated with the data fetched from the database, you have to create a new plugin for that, I'd suggest you to take a look at the customfields one, inside the group ATS

Davide Tampellini

Developer and Support Staff

🇮🇹Italian: native 🇬🇧English: good • 🕐 My time zone is Europe / Rome (UTC +1)
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!