<p>I've updated the Sprout docs with <a href="https://sprout.barrelstrengthdesign.com/docs/forms/events-and-hooks.html" rel="nofollow noreferrer">examples of Craft 3 events and hooks</a>. </p>

<p>In your case, the Form Entry Element extends the <code>craft\base\Element</code> class and also supports the same after the base element save event: <code>EVENT_AFTER_SAVE</code>. In your primary plugin class <code>init</code> method:</p>

<pre><code>use barrelstrength\sproutforms\elements\Entry;
use yii\base\Event;
use Craft;

public function init()
{
    parent::init();

    Event::on(Entry::class, Entry::EVENT_AFTER_SAVE, function(Event $event) {
        if (Craft::$app-&gt;request-&gt;isSiteRequest)
        {
            // A Form Entry Element has been saved from a Front-end Form Submission
            Craft::dd($event-&gt;sender);
        }

        if (Craft::$app-&gt;request-&gt;isCpRequest)
        {
            // A Form Entry Element has been updated from the Control Panel

            Craft::dd($event-&gt;sender);
        }
    });
}
</code></pre>

<p>You can access the specific Form Entry Element being submitted via the <code>$event-&gt;sender</code> property.</p>

CC BY-SA 4.0
2018-06-15T08:45:46.190Z
Could you expand the example to show how to interact with the entry/form itself? I've tried `$event->entry` and `$event->params['entry']`, but neither works.
peirix
CC BY-SA 4.0
2018-06-15T13:34:09.517Z
@peirix I realize my first example was for a Form Element not a Form Entry Element. I've updated the example and added bit more info on where you can find the Element in the event.
Ben Parizek
CC BY-SA 4.0
2018-06-14T02:55:42.367Z
2018-06-15T13:33:00.433Z
2018-06-15T13:33:00.433Z
Ben Parizek
<p>I've built lots of Craft 2 plugins that catch Sprout Forms submissions and integrate with external services (CRM's etc). It was easy, you'd make a plugin and catch the event going:</p>

<pre><code>craft()-&gt;on('sproutForms.onSaveEntry', function(SproutForms_OnSaveEntryEvent $event) {
    // Hand submission off to your service to do some rad stuff.
});
</code></pre>

<p>But in Craft 3, that events functionality appears to be more complicated. All the <a href="https://sprout.barrelstrengthdesign.com/docs/forms/events-and-hooks.html" rel="nofollow noreferrer">Events &amp; Hooks area in the Sprout Documentation</a> just show "Example needed." in all the places where code samples would usually be. The <a href="https://docs.craftcms.com/v3/updating-plugins.html#events" rel="nofollow noreferrer">Craft 3 plugin docs on events</a> show a new system for registering and intercepting events - but my coffee deficient mind is struggling to figure out how to map that to Craft3/Sprout Forms 3.0.0-beta.17.</p>

<p>Has anyone built a Craft 3 plugin that works with Sprout Forms Beta yet? I'm even struggling to find examples of any event integration in plugins at the moment.</p>

<p>Halp!!!</p>

<plugin-development><craft3><plugin-sproutforms>
Intercepting Sprout Forms "onSaveEntry" Event In Craft 3 Plugin
# Intercepting Sprout Forms "onSaveEntry" Event In Craft 3 Plugin

(Asked by: username_0 on 2018-06-13)

I've built lots of Craft 2 plugins that catch Sprout Forms submissions and integrate with external services (CRM's etc). It was easy, you'd make a plugin and catch the event going:
craft()->on('sproutForms.onSaveEntry', function(SproutForms_OnSaveEntryEvent $event) {
    // Hand submission off to your service to do some rad stuff.
});

But in Craft 3, that events functionality appears to be more complicated. All the Events & Hooks area in the Sprout Documentation just show "Example needed." in all the places where code samples would usually be. The Craft 3 plugin docs on events show a new system for registering and intercepting events - but my coffee deficient mind is struggling to figure out how to map that to Craft3/Sprout Forms 3.0.0-beta.17.
Has anyone built a Craft 3 plugin that works with Sprout Forms Beta yet? I'm even struggling to find examples of any event integration in plugins at the moment.
Halp!!!

**Tags:** plugin-development, craft3, plugin-sproutforms


---

## 1 answers

### Answer by username_1 on 2018-06-14. Score: 2 | Accepted answer

I've updated the Sprout docs with examples of Craft 3 events and hooks. 
In your case, the Form Entry Element extends the craft\base\Element class and also supports the same after the base element save event: EVENT_AFTER_SAVE. In your primary plugin class init method:
use barrelstrength\sproutforms\elements\Entry;
use yii\base\Event;
use Craft;

public function init()
{
    parent::init();

    Event::on(Entry::class, Entry::EVENT_AFTER_SAVE, function(Event $event) {
        if (Craft::$app->request->isSiteRequest)
        {
            // A Form Entry Element has been saved from a Front-end Form Submission
            Craft::dd($event->sender);
        }

        if (Craft::$app->request->isCpRequest)
        {
            // A Form Entry Element has been updated from the Control Panel

            Craft::dd($event->sender);
        }
    });
}

You can access the specific Form Entry Element being submitted via the $event->sender property.

> **Comments:**
> **username_2**: Could you expand the example to show how to interact with the entry/form itself? I've tried `$event->entry` and `$event->params['entry']`, but neither works.  
> **username_1**: @username_2 I realize my first example was for a Form Element not a Form Entry Element. I've updated the example and added bit more info on where you can find the Element in the event.  

---

