How to pass data from a dialog to submit()

,

Hello everyone!

I’m reading this document Panel dialogs | Kirby CMS
and I can’t figure out how to pass data from the dialog to submit().

For example, I have a select component in my dialog with a list of pages. How do I pass the selected value from the list?

<?php

use Kirby\Cms\App as Kirby;
use Kirby\Cms\Find;

Kirby::plugin('my/file-move', [
    'areas'        => [
        'site' => function ($kirby) {
            return [
                'dropdowns' => [
                    'page.file' => function (string $path, string $filename) use ($kirby) {
                        $file = Find::file($path, $filename);

                        if (! $file) {
                            return [];
                        }

                        $dropdown = $file->panel()->dropdown();

                        $dropdown[] = '-';

                        $dropdown[] = [
                            'icon'   => 'parent',
                            'text'   => t('file.move'),
                            'dialog' => 'file/' . $file->id() . '/move',
                        ];

                        return $dropdown;
                    }
                ],
                'dialogs'   => [
                    'file.move' => [
                        'pattern' => 'file/(:all)/(:any)/move',
                        'load'    => function (string $path, string $filename) use ($kirby) {
                            $page = Find::page($path); 
                            $file = $page->files()->find($filename);
                            $parents   = $kirby->site()->index();

                            $options = [];
                            foreach ($parents as $model) {
                                $options[] = [
                                    'text'  => str_repeat("— ", $model->depth() - 1) . ' ' . $model->title()->value() . ' (/' . $model->id() . ')',
                                    'value' => $model->id(),
                                ];
                            }

                            return [
                                'component' => 'k-form-dialog',
                                'props'     => [
                                    'fields' => [
                                        'parent' => [
                                            'label'   => t('select.parent'),
                                            'type'    => 'select',
                                            'icon'    => 'parent',
                                            'options' => $options,
                                            'empty'   => false,
                                        ],
                                    ],
                                    'value'  => [],
                                ],
                            ];
                        },
                        'submit'  => function (string $path, string $filename) use ($kirby) {
                            $parent = $kirby->request()->get('parent');

                            if (empty($parent) === true) {
                                throw new InvalidArgumentException('Please select parent page!');
                            }

                            $parent = Find::page($parent);
                            Panel::go($parent->panel()->url());
                            return true;
                        },
                    ]
                ],
            ];
        },
    ],
    'translations' => [
        'en' => [
            'file.move'     => 'Move',
            'select.parent' => 'Select folder',
        ],
    ],
]);

You can use the get helper to get all data from all fields:

$data = get();

Picking a single value like this should also work:

$parent = get('parent');

Hello, texnixe!

Thanks for the quick response. I tried get() and get('parent'), and neither returned anything. I checked this way:

$data = get();
file_put_contents('tmp/file.move.submit.txt', print_r($data, true));

And I got the file file.move.submit.txt

Array
(
)