Max,
I have a record that may contain i.e. the following: ["X", "Y", "Abcd", "1234"].
I guess this is a json record. What I want is to use each of the data to populate a dropdown, if the record is not X. If it is do anything else.Have you a suggestion?.
Thanks
is not this the same question here:
?
Max, no this was a similar question, but I managed to solve. For the sake of information, here the solution I found:here the form:
and here the php109:
$json = $this->data['einsteige_ort'];
// Wenn NULL oder leer → direkt "hat x"
if (empty($json)) {
return "hat x";
}
// Versuche JSON zu dekodieren
$dataArray = json_decode($json, true);
// Fallback, falls JSON ungültig
$dataArray = is_array($dataArray) ? $dataArray : [];
// Prüfen, ob "X" enthalten ist
return in_array("X", $dataArray) ? "hat x" : "kein x";
and the php152
$json = $this->data['einsteige_ort'];
$dataArray = json_decode($json, true);
// Fallback, falls JSON ungültig
$dataArray = is_array($dataArray) ? $dataArray : [];
// Filter: Entferne "X", leere Strings, null und 0
$filtered = array_filter($dataArray, function($item) {
return $item !== "X" && $item !== '' && $item !== 0 && !is_null($item);
});
// Formatieren für Dropdown
$options = array_map(function($item) {
return ["value" => $item, "text" => $item];
}, array_values($filtered));
// Leere Option am Anfang einfügen
array_unshift($options, ["value" => "", "text" => "--- bitte wählen ---"]);
return $options;
this way i check if einsteige_ort contains an "X" and if yes, than only a text field is visible.
if anything else , 1 or more options are in the einsteige_ort, all options are in the dropdown for the users selection.
Hope it helps someone else.
Great, thank you for sharing the solution! 😊
