<p>Only thing I can think of off the top of my head would be to create a new, separate database table that stores user Ids against email addresses. Perhaps also with a timestamp of when the row was written.</p>

<p>You can then write the user's email address to that upon registration and use it to check against the "official" email address when you need to.</p>

<p>If you find a change, do whatever it is you need to do and update your table with the new email address.</p>

CC BY-SA 4.0
2018-12-13T09:00:13.920Z
2018-12-13T09:00:13.920Z
foamcow
<p>I'm trying to determine if a user has changed their email address via a front-end form. From what I've gleaned, the best way to do this would be by checking the existing record during <code>users.beforeSaveUser</code>, store the old email, then compare to the new email during <code>users.onSaveUser</code>.</p>

<p>However, when I get a user's record during <code>users.beforeSaveUser</code>, the newly-submitted email address has already overwritten their record.</p>

<pre><code>craft()-&gt;on('users.beforeSaveUser', function(Event $event)
{
    if(!$event-&gt;params['isNewUser'])
    {
        $currentUser = craft()-&gt;users-&gt;getUserById($user-&gt;id);
        exit($currentUser-&gt;email);
    }
}
</code></pre>

<p>This code shows the new email, not the old one.</p>

<p>Is this expected behaviour? Any other way to accomplish what I need to?</p>

<users><frontend-form><craft2>
How to determine if a user's email has changed
# How to determine if a user's email has changed

(Asked by: username_0 on 2018-12-12)

I'm trying to determine if a user has changed their email address via a front-end form. From what I've gleaned, the best way to do this would be by checking the existing record during users.beforeSaveUser, store the old email, then compare to the new email during users.onSaveUser.
However, when I get a user's record during users.beforeSaveUser, the newly-submitted email address has already overwritten their record.
craft()->on('users.beforeSaveUser', function(Event $event)
{
    if(!$event->params['isNewUser'])
    {
        $currentUser = craft()->users->getUserById($user->id);
        exit($currentUser->email);
    }
}

This code shows the new email, not the old one.
Is this expected behaviour? Any other way to accomplish what I need to?

**Tags:** users, frontend-form, craft2


---

## 1 answers

### Answer by username_1 on 2018-12-13. Score: 1

Only thing I can think of off the top of my head would be to create a new, separate database table that stores user Ids against email addresses. Perhaps also with a timestamp of when the row was written.

You can then write the user's email address to that upon registration and use it to check against the "official" email address when you need to.

If you find a change, do whatever it is you need to do and update your table with the new email address.


---

