Dynamic dropdown

Find out how to set select field options based on a database field value.

kraadde 18 Apr, 2025

Max, one tricky problem.

I have a data field with 0 to 8 comma separated values which i want to use to popolate a dropdown field. The data field changes dynamically therefore, i have not found an easy solution. Any hint?

Max_admin 18 Apr, 2025

the field is on the same form page ? or is it a database table field ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kraadde 18 Apr, 2025

it is a database field. 

Max_admin 19 Apr, 2025

so you need the dropdown to have these options when the form page is loaded ? or how should this work ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kraadde 19 Apr, 2025

Yes, I need to have these options when the page is loaded. The options in the database field (varchar(63)) may look like that: ["R","G","T"] or have more options.

Max_admin 05 May, 2025
Answer

The easiest way is to get the variable from Read Data and prepare it in a PHP action in the format supported by the Dynamic Options behavior, the dynamic options behavior requires an associative array, so your PHP code can be like this:

$return = [];
foreach($this->get("read_data.column") as $k => $v){
$return[] = ["id" => $v, "text" => $v];
}

return $return;

And your Dynamic Options will be like this:

Dynamic dropdown image 1

just change the "php_name" to the real name of your PHP action

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.

VPS & Email Hosting 20% discount
hostinger