Add to data in log file using Uniform

Hi,

I am using Uniform for handling a form submission, and as part of this I am storing the submission in a log file.

I am adding some data in to the email, and would like to also add this to the log file. Is it possible to append this additional data so it appears in the log?

Below is my controller:

<?php

use Uniform\Form;

return function ($kirby, $page)
{
    $form = new Form([
        'email' => [
            'rules' => ['required', 'email'],
            'message' => 'Please enter a valid email address',
        ],
        'forename' => [
            'rules' => ['required'],
            'message' => 'Please enter your first name',
        ],
        'surname' => [
            'rules' => ['required'],
            'message' => 'Please enter your last name',
        ],
    ]);

    if ($kirby->request()->is('POST')) {
        $form->honeypotGuard()->honeytimeGuard([
            'key' => c::get('uniform.honeytime.key'),
            'seconds' => 3,
          ])->logAction([
            'file' => kirby()->roots()->site().'/applications.log',
          ])->emailAction([
            'to' => 'me@example.com',
            'from' => 'info@example.com',
            'template' => 'simple',
            'subject' => 'New application for '. $page->title() . ' role for ' . $page->client(),
            'data' => [
                'role' => $page->title(),
                'client' => $page->client(),
                'job ID' => $page->jobId(),
            ],
        ])->done();
    }

    return compact('form');
};

You could create a custom log action that basically does the same as the current log action, but you would allow passing a data array to it and merge that with the form data. Take a look at the original action to see what it does, and the docs of the plugin how to create a custom action.

When referring to a plugin, please always add a link for easier reference, thanks.

Cool, thank you. And thanks for the pointer about including a link

Just for any future travellers, I actually solved this by doing the following:

<?php

use Uniform\Form;

return function ($kirby, $page)
{
    $form = new Form([
        'email' => [
            'rules' => ['required', 'email'],
            'message' => 'Please enter a valid email address',
        ],
        'forename' => [
            'rules' => ['required'],
            'message' => 'Please enter your first name',
        ],
        'surname' => [
            'rules' => ['required'],
            'message' => 'Please enter your last name',
        ]
    ]);

    if ($kirby->request()->is('POST')) {

        $form->data('role',$page->title());
        $form->data('client',$page->client());
        $form->data('job_id',$page->jobId());

        $form->honeypotGuard()->honeytimeGuard([
            'key' => c::get('uniform.honeytime.key'),
            'seconds' => 3,
        ])->validate();
          
        if($form->success()):

            $form->logAction([
                'file' => kirby()->roots()->site().'/applications.log',
            ]);
          
            $form->emailAction([
                'to' => 'me@example.com',
                'from' => 'info@example.com',
                'template' => 'simple',
                'subject' => 'New application for '. $page->title() . ' role for ' . $page->client(),
            ])->done();

        endif;
    }

    return compact('form');
};

Which adds the additional data so it appears in both the log file and the email