Forums

Checkboxes from data array not working

zest96 8d ago

Hi,

I cannot make Dynamic Checkboxs work. This is the output:

The dynamic options do not populate the checkboxs.

if I put this: {var:php_10.2.value}   (or any other key) it shows one checkbox.

if I put this: {var:php_10.value}  - shows nothing.

  [php_10] => Array
        (
            [returned] => Array
                (
                    [0] => Array
                        (
                            [value] => norte
                            [text] => norte
                        )

                    [1] => Array
                        (
                            [value] => valley
                            [text] => valley
                        )

                    [2] => Array
                        (
                            [value] => center
                            [text] => center
                        )

                    [3] => Array
                        (
                            [value] => south
                            [text] => south
                        )

                   

                )

            [var] => Array
                (
                         [0] => Array
                        (
                            [value] => norte
                            [text] => norte
                        )

                    [1] => Array
                        (
                            [value] => valley
                            [text] => valley
                        )

                    [2] => Array
                        (
                            [value] => center
                            [text] => center
                        )

                    [3] => Array
                        (
                            [value] => south
                            [text] => south
                        )

                )

        )
Elita 8d ago

Zest96,

Did you check out the demo form that Max created?

Specifically, the Dynamic Options? There's an example for a Checkbox Group and a PHP action that returns an array.

I haven’t tested it yet, but it looks pretty straightforward to me.

Elita

zest96 8d ago

Which CF?

I can't install cf8. must finish this in cf7 or 6

there is no checkboxs demo in CF7, nor CF6

whever I do, something isn't working right. I cannot know if it's a bug, or my misunderstanding.

I've put so much time on it, it's frustrating.

Elita 8d ago

Ahh... my bad. I'm already in CF8 mode! 😆

More information is needed - are we talking about CF6 or CCv6? Which version exactly?

But in general, if you set {var:php_10.2.value}, it will display the array item with the key value 2.If you want to show the entire returned array, you’ll need to loop through it (or use a loop event function) to display all [value] or [text] items.

The idea of how to use a loop and an array is explained here:🔗 How to use the Repeater Area

Or this example for file uploads with a repeater:🔗 Custom File Upload with Repeater & Saving Filenames as Separate Rows

Elita

zest96 8d ago

Thanks!!

What should the var look like so I wont need to loop it and use: {var:php_10.value} in options value and text?

cause I can change the php to return different array.

or maybe, because it's custom php, CC7/6 don't accept it?

this is my php that gets the values from joomla Jcfield "fieldparams"

$fieldParamsJson = $this->get("read_locations.0.Locations.fieldparams");

$fieldParamsArray = json_decode($fieldParamsJson, true);

$optionsArray = $fieldParamsArray['options'] ?? [];

$checkboxOptions = [];
foreach ($optionsArray as $option) {
    $checkboxOptions[] = [
        'value' => $option['value'],
        'text'  => $option['name']
    ];
}

//return $checkboxOptions;
return json_encode($checkboxOptions, JSON_UNESCAPED_UNICODE);
zest96 8d ago

this is my sql query (phpmyadmin)SELECT `publisher` FROM `rrbc_books` WHERE `year`IN (2008)

what is the syntax here? nothing works

You need to login to be able to post a reply.