Use external source for Dropdown options

How to populate dropdown options from an external source.

Overview

The issue is that dropdown options need to be updated across multiple forms when data changes frequently.
Read the external data into a PHP array and assign it to a specific variable within a CF PHP action placed before the dropdown element.

Answered
ChronoForms v8
oa oandm765 17 Oct, 2024

Hello,

Is there a way to pull data from a different source (excel / google sheets) and have those populate the drop down options for a field?

Backstory: My form lists multiple locations in a dropdown list, and those locations change frequently. Since I am going to have multiple forms on the website which will need the same location list, It would be easier to have one location where it is updated instead of changing it in each form. Is something like this possible?

Thank you!

Max_admin Max_admin 18 Oct, 2024
Answer

you may use a Google sheet or you may read from a file, any file can work, just write the PHP needed to read the data from the file and convert it to a PHP array which you will set inside a specific variable that can be used as the data source for your dropdowns, the same code can be pasted in every form:

// code to read the file and return a PHP array like this: $array = [["value" => "1", "text" => "first"]];
$this->set("dropdown_values", $array);

after building the code above and adding inside a PHP action, you may use this as the data source for your dropdown:

Use external source for Dropdown options image 1

make sure the PHP action is always above the dropdown, you may also place the PHP code in a .php file and just require it in the PHP action

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.