<p>I believe you're looking for this instead.</p>
<pre><code>Event::on(
    Entry::class,
    Element::EVENT_AFTER_SAVE,
    static function (ModelEvent $event) {
        $entry = $event-&gt;sender;
        if ($entry-&gt;status === 'disabled'
            &amp;&amp; $entry-&gt;propagating
            &amp;&amp; $entry-&gt;resaving
            &amp;&amp; ElementHelper::isDraftOrRevision($entry)) {
            return; // do nothing if disabled/draft/resaving...
        }
        if ($entry-&gt;section-&gt;handle === 'my-handle') { // check section handle
            // call your preferred msg client: slack, email, mailgun...
        }
    }
);
</code></pre>

CC BY-SA 4.0
2021-04-15T17:21:27.320Z
2021-04-15T17:21:27.320Z
Leo Leoncio
<p>I want to send an email if/when an entry is saved with a lightswitch switched on after previously being off.</p>
<p>I have the below code in my plugin's init file, but I don't know how to</p>
<ol>
<li><p>check for the section uid and verify that it's the right section or</p>
</li>
<li><p>check the previous value and compare it to the value being saved.</p>
</li>
</ol>
<pre><code>    Craft::$app-&gt;elements-&gt;on(Elements::EVENT_AFTER_SAVE_ELEMENT, function(ElementEvent $e) {
            $element = $e-&gt;element;
            
            
    
        });
</code></pre>
<p>I'd appreciate any help, thanks.</p>

<plugin-development><entries><events>
Listening for Change at Entry Save
# Listening for Change at Entry Save

(Asked by: username_0 on 2021-02-27)

I want to send an email if/when an entry is saved with a lightswitch switched on after previously being off.
I have the below code in my plugin's init file, but I don't know how to

check for the section uid and verify that it's the right section or

check the previous value and compare it to the value being saved.


    Craft::$app->elements->on(Elements::EVENT_AFTER_SAVE_ELEMENT, function(ElementEvent $e) {
            $element = $e->element;
            
            
    
        });

I'd appreciate any help, thanks.

**Tags:** plugin-development, entries, events


---

## 1 answers

### Answer by username_1 on 2021-04-15. Score: 1

I believe you're looking for this instead.
Event::on(
    Entry::class,
    Element::EVENT_AFTER_SAVE,
    static function (ModelEvent $event) {
        $entry = $event->sender;
        if ($entry->status === 'disabled'
            && $entry->propagating
            && $entry->resaving
            && ElementHelper::isDraftOrRevision($entry)) {
            return; // do nothing if disabled/draft/resaving...
        }
        if ($entry->section->handle === 'my-handle') { // check section handle
            // call your preferred msg client: slack, email, mailgun...
        }
    }
);


---

