Uniform logging error

Hi all - I have a small website with a contact form using Uniform built in Kirby 2. I really need to keep it in Kirby v2 for now because it uses a few plugins and structures that would be a lot of time to change for now and it’s not really budgeted for within the project. I’m trying to get logging working and have used the docs to end up with the below. However I get ‘Call to undefined method UniForm::logAction()’. Does anyone know where I’ve gone wrong?

<?php

return function($site, $pages, $page) {

   $form = uniform('contact-form', array(
         'required' => array('_from' => 'email'),
         'actions'  => array(
            array(
               '_action' => 'email',
               'to'      => 'to@email.com',
               'sender'  => ''sender@email.com'',
            )
         )
      )
            );

            if (r::is('POST')) {
               $form->logAction([
                   'file' => kirby()->roots()->site().'/messages.log',
               ]);
           }

   return compact('form');
};

Which version of the uniform plugin are you using? Your code looks a bit outdated.

I’m using v4.2.0 which is the latest for Kirby 2.
The form function is taken from here which the github docs say to use and I’ve added the log action below.

It seems the latest version for Kirby 2 is v3.5.0.

If that doesn’t solve the problem, try using the class syntax: Log - Kirby Uniform

Thanks @pedroborges - I can’t see anything on that link that I recognise as a class syntax, so might need further help pointing that out, but the controller there is a little different to what i have from their first setup example. However I can’t see in that where I would define the to and from emails?

I meant PHP class syntax like $form = new Uniform\Form;

You can chain actions inside the if statement. to and from are defined in the emailAction.

Thanks @pedroborges - So I think that’s what i had originally, but I get
"Class ‘Uniform\Form’ not found"

<?php 

use Uniform\Form;

return function ($kirby)
{
    $form = new Form([
        'email' => [
            'rules' => ['required', 'email'],
            'message' => 'Email is required',
        ],
        'message' => [
            'rules' => ['required'],
            'message' => 'Message is required',
        ],
    ]);

    if ($kirby->request()->is('POST')) {
        $form->emailAction([
            'to' => 'info@me.co.uk',
            'from' => 'info@me.co.uk',
        ]);
    }

    if ($kirby->request()->is('POST')) {
      $form->logAction([
          'file' => kirby()->roots()->site().'/messages.log',
      ]);
  }

    return compact('form');
};

Make sure the plugin is properly installed and loaded. If you downloaded the plugin from Github, you will need to rename the plugin folder to uniform. In Kirby 2 the folder needs to match the main PHP filename, uniform.php.