Use external source for Dropdown options

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 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.
You need to login to be able to post a reply.