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:
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!