Buy Now
Sign in

FAQ search

Dynamic dropdown options

Published: Friday, 26 May 2017 14:15

In CFv6 in order to load a dropdown's options from the database, you need to follow the steps below:

  1. Add a Read Data action under the setup section and make sure that its above the Display Section action.
  2. Open the Read Data settings, choose the table you want to load the data from, set the "Select type" to "Key/value pairs array" and in the "Fields to retrieve" add the two field names you want to use for the dropdown options values and labels respectively. Or, if you want to use the same field for both value and label add just that name.
  3. Take a note of the Read Data action name, it's inside a black label, let's assume it is set to "read_data1", go to the dropdown, and write the following in the "options" box:

Please note that any array can be used to populate a dropdown the same way, as long as the variable called in the options box returns an array, so for example, you can use the following PHP code inside a PHP function instead of using a "Read Data" action:

$options = ["y" => "Yes", "n" => "No"];
return $options;

assuming the PHP function name is "php1", you can use {var:php1} to populate the dropdown options.