How to use data entered in form in a plugin for a custom process action

I have a form with a custom action that gets processed via a plugin. I want to send a customised email. However, I do not know how to access the values that are contained in the Data object…

My code looks like this:

    public function onFormProcessed(Event $event)
    {
        $form = $event['form'];
        $action = $event['action'];
        $params = $event['params'];

        switch ($action) {
            case 'emailafile': // my custom action
                $data = $form->Data;
                dump($data); exit;
                $to = 'my@test.address';
                $from = 'my@test.address';

                $subject = 'Test!';
                $content = 'mehr Test…';
                $filename = ROOT_DIR . 'path/to/file.pdf';

                $message = $this->grav['Email']->message($subject, $content, 'text/html')
                    ->setFrom($from)
                    ->setTo($to)
                    ->attach(\Swift_Attachment::fromPath($filename));

                $sent = $this->grav['Email']->send($message);
        }
    }

The emailing code works nicely, I only need to figure out how to insert the variables from the form. So this `dump($data)’ above gives me the following output:

Data-dump
And the #items bit contains everything I need – but how do I access it in PHP? I have tried:

$data->items
$data['items']

and a few other wild guesses, but to no avail. Can somebody help me out here please? Maybe there’s a plugin that handles form data where I could take a look?

Thank you for your time!

Hey, I got this bit figured out! $form->value('fieldname') gets me whatever I need. :smiley: I’m now stuck on something else (of course), but that shall have its own thread…

You can even access form values from forms that you have not created with YAML, but your own HTML forms. But you need to add soemthing with “data” to the value attribute. Check out how Grav (Form plugin) generates the input fields.