json records

kraadde 24 Jul, 2025

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

kraadde 29 Jul, 2025
Answer
1 Likes

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.

Max_admin 31 Jul, 2025

Great, thank you for sharing the solution! 😊

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.