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);
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 ?
I tried "{row:value} for Value and {row:text} for Text" but the dropdown remains empty.
In the image you do not have that, and does the PHP run BEFORE the dropdown ?
The order is correct, try to return the array directly without json encoding, the json is needed for AJAX results only
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)
)
Enter any string in Value & Text, like 1 and 2, do you get options list or the dropdown has no selections ?
<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>
Do you have {row:value} and {row:text} now ? because your screenshot does not have that
Aha, now I understand.
That was the solution. :-)It works.
Thank you very much!
Great! :)
