1

I am writing a new plugin to hook into a POST event from a bespoke form plugin called "Capture". The Capture plugin fires two different events; the code taken from /craft/plugins/capture/services/Capture_SubmissionsService.php

public function onBeforePost(Event $event) {
    $this->raiseEvent('onBeforePost', $event);
}

public function onPost(Event $event) {
    $this->raiseEvent('onPost', $event);
}

I called die(); inside each one so I know they are being called.

My new plugin is very simple. I would like to be able to hook into the onPost event and receive the form data. My plugin is very simple for now as I am just concerned with hooking into the event. The below example has getName, getDeveloper, getDescription, getVersion etc removed for ease of reading. This is the only file in my plugin: /craft/plugins/myplugin/MyPlugin.php

<?php
namespace Craft;

class MyPlugin extends BasePlugin {

   public function init() {
      craft()->on('capture.onPost', function(Event $event){
         die('onPost <pre>'.print_r($event,true).'</pre>');
      });
   }
}

But this doesn't seem to be get called. I am assuming that I need something other than capture.onPost.

I have used the following docs, but would appreciate any help.

https://craftcms.com/docs/plugins/hooks-and-events

https://craftcms.com/docs/plugins/events-reference

  • Might sound like a silly question, but is MyPlugin installed and enabled in the Craft control panel? – Brad Bell May 25 '16 at 12:04
  • Yes it is. I think I have found my problem now and will post as an answer. Thank you – Alex Holsgrove May 25 '16 at 12:09
1

I found the answer in a bit of a clumsy way, but the capture plugin has two services, capture_forms and capture_submissions. The first deals with saving the forms within the CraftCMS admin, the latter is for dealing with the form submissions.

I had to simply change my listener to craft()->on('capture_submissions.onPost', function(Event $event){...}); and I can see the event data.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.