1

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?

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.

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.