Dynamic Options with PHP

populate a CF dropdown with dynamic PHP data.

Overview

The dropdown was empty because the placeholder syntax in the dropdown settings was incorrect.
In the dropdown's Data Source settings, ensure the Value field uses {row:value} and the Text field uses {row:text} to match the structure of the returned PHP array.

Answered
ChronoForms v8
Fr Fredolino 27 Oct, 2025

I have a dropdown menu with dynamic data from a PHP code (load_arten).

Why is the dropdown menu empty?

Dropdown:

Data Source: {var:load_arten}

Value: {row:art_id}

Text: {row:artname}

Im Debugger (Info):

Array
(
    [load_arten] => Array
        (
            [returned] => [
    {
        "value": 7562,
        "text": "Abraxas grossulariata (LINNAEUS, 1758)"
    },
    {
        "value": 1000,
        "text": "Acanthopsyche atra (LINNAEUS, 1767)"
    },
. . .

PHP code (load_arten):

. . .
$options = [];
foreach ($rawOptions as $value => $text) {
    $options[] = ['value' => $value, 'text' => $text];
}
return json_encode($options, JSON_PRETTY_PRINT);
Max_admin Max_admin 27 Oct, 2025

You have the values returned as an array with "value" and "text" keys, so you can just use {row:value} for Value and {row:text} for Text

Does this work ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Fr Fredolino 27 Oct, 2025

I tried "{row:value} for Value and {row:text} for Text" but the dropdown remains empty.

Bildschirmfoto.jpg
Max_admin Max_admin 28 Oct, 2025

In the image you do not have that, and does the PHP run BEFORE the dropdown ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin Max_admin 28 Oct, 2025

The order is correct, try to return the array directly without json encoding, the json is needed for AJAX results only

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Fr Fredolino 28 Oct, 2025

I tried that first, and it didn't work.

$options = [];
foreach ($rawOptions as $value => $text) {
    $options[] = ['value' => $value, 'text' => $text];
}

debug:

Array
(
    [app_active_page] => -1
    [load_arten] => Array
        (
            [0] => Array
                (
                    [value] => 7562
                    [text] => Abraxas grossulariata (LINNAEUS, 1758)
                )

            [1] => Array
                (
                    [value] => 1000
                    [text] => Acanthopsyche atra (LINNAEUS, 1767)
                )
Max_admin Max_admin 28 Oct, 2025

Enter any string in Value & Text, like 1 and 2, do you get options list or the dropdown has no selections ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Fr Fredolino 28 Oct, 2025
<select name="dp_species" id="dp_species" class="noselection" data-menuclass="nui grid stackable horizontal columnx1" data-searchable="1">
    				<option value="0">Art auswählen</option>
							<option value=""></option>
							<option value=""></option>
							<option value=""></option>

			</select>
Max_admin Max_admin 28 Oct, 2025
Answer

Do you have {row:value} and {row:text} now ? because your screenshot does not have that

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Fr Fredolino 29 Oct, 2025

Aha, now I understand.

That was the solution. :-)It works.

Thank you very much!

Max_admin Max_admin 29 Oct, 2025

Great! :)

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Post a Reply