Hello everyone, I have the following problem. I have a table that I output in CF8, and based on the FAQ, I’ve set up an edit page and mapped the fields in it. So far, so good. However, I have a checkbox group that is not being pre-selected correctly. What do I need to enter into the SelectedValue
to correctly assign the data read from the database?
An example:read_data7
returns the following:
Array (
[option] => com_chronoforms8 [action] => view [chronoform] => fahrer [chronopage] => bearbeiten [id] => 54 [name] => Tester [vorname] => Test [kat] => ["B","C"] )
The kat
field is the selection, and I would like it to be pre-selected in the edit section so that I can also modify it.
Thanks for a quick response.
Best regards,bambid
Hi bambid
you should enter in the Selected Values:
{var:read_data7.kat}
But I think this is the same issue reported in the topic below, it has been fixed but the fix requires the new update:
Hello Max,
Thanks for your reply. I have the latest version 8.0.37, but
{var:read_data7.kat}
is not working.
Do you have any further suggestions?
bambid
the new update is out, please try the fix now and let me know!
Hello Max,I have now installed version 39, but there is no change. If I select only one option, it works. However, if I select multiple options, none are selected.
Here is my PHP code that generates the output:
$katJson = $this->data['kat'] ?? '';
// JSON-String sicher in ein PHP-Array konvertieren
$katArray = json_decode($katJson, true);
// Prüfen, ob die Umwandlung erfolgreich war
if (is_array($katArray)) {
return implode(" ", $katArray);
}
The result is as follows:
B C
Even with:
$katJson = $this->data['kat'] ?? '';
// JSON-String sicher in ein PHP-Array konvertieren
$katArray = json_decode($katJson, true);
// Prüfen, ob die Umwandlung erfolgreich war
if (is_array($katArray)) {
return implode(",", $katArray);
}
The result is as follows:
B,C
it doesn't work.
My Array looks like:
Array
(
[option] => com_chronoforms8
[action] => view
[chronoform] => fahrer
[chronopage] => bearbeiten
[id] => 67
[order_by] => name:asc
[name] => Muster
[vorname] => Paul
[kat] => ["B","C"]
)
Can you tell me if I am doing anything else wrong?
Kind regards bambid
You do not need to decode, you can add your column to the JSON fields list in the Read Data
This setup works for me:
This is the result:
Hello MaxThx. With the following Code it works:
$katJson = $this->data['kat'] ?? '';
// JSON-String sicher in ein PHP-Array konvertieren
$katArray = json_decode($katJson, true);
// Prüfen, ob die Umwandlung erfolgreich war
if (is_array($katArray)) {
return $katArray; // Direkt das Array zurückgeben
}
Kind regards
Thanks for sharing the solution.
I'm not sure how do you get data["kat"] but if its from the db table then you can use the json fields directly
Hello Max,
Thank you! But the direct way via {var:read_data7.kat} doesn’t work for me, even though both outputs are the same when I display them in a text field.
kind regards
did you add kat to the JSON Fields in your Read Data ?
it will show in the debug under read_data7 as
["B","C"]
if you had it setup correctly
Hello Max, here is a picture.
The upper part is generated via PHP, and the lower part is created using readdata. The output in the text field is what I have also stored in the selected option, but it doesn't seem to work.
Could it be due to the characters? I can't imagine that, but anything is possible. ;-)
Best regards,Bambid