Jump to:

22996 Posts in 11844 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Send email notification after editing a member's details?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1110 Views
  • flipsidenz
    Avatar
    Community Member
    49 Posts

    Send email notification after editing a member's details? Link to this post

    For members in my site, I have set a status field. The idea is that admins can login to the CMS and set a newly registered member from 'Disabled' to 'Enabled'.

    What I am wanting to do is have an email be sent out to a member when their status is updated to enabled...

    Admins are using the security tab in the CMS to achieve this.

    How would I go about having an email fire off when an admin updates their status to 'Enabled'?

    Thanks.

  • flipsidenz
    Avatar
    Community Member
    49 Posts

    Re: Send email notification after editing a member's details? Link to this post

    Just letting anyone whose interested know I came across this post: http://silverstripe.org/general-questions/show/12197

    One thing I am unsure about though....

    If I add an onAfterWrite function into my decorator, how do I call the Member DataObject's native onAfterWrite function first? Those examples use parent::onAfterWrite();.....but I thought it would have been $this->owner->onAfterWrite(); ?

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: Send email notification after editing a member's details? Link to this post

    I was able to set up something similar. When a registered user is marked 'Enabled' by an admin it emails the registered member.

    I'm not sure how you are trying to do this, but inside my MediaMember.php I have a onAfterWrite() function that handles the emailing. the parent::onAfterWrite() handles everything else.

    class MediaMember extends DataObjectDecorator {
    ...
    function onAfterWrite() {
          if($this->checkStatus == 'Disabled' && $this->owner->Status == 'Enabled') {
             if($this->selUser->inGroup('media-access')) {
                $email = new Email();
                $email->setTo($this->owner->Email);
                $email->setSubject('Account Enabled');
                $email->setFrom('no_reply@mysite.com');
                $email->setTemplate('AccessGranted');
                $email->populateTemplate($this->owner);
                $email->send();
             }
          }
          parent::onAfterWrite();
       }
    }

    you shouldn't have to call the member's dataObject as you are in the DataObjectDecorator which references the Member you are currently editing. $this->owner is the member's dataobject.

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Send email notification after editing a member's details? Link to this post

    You don't need to call parent::onBeforeWrite() (or after) in any decorators as the actual function (onBeforeWrite) will already be the callee. You only need to explicitly call it when you're subclassing a dataobject (not decorating)

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: Send email notification after editing a member's details? Link to this post

    makes sense, this is good to know.

  • flipsidenz
    Avatar
    Community Member
    49 Posts

    Re: Send email notification after editing a member's details? Link to this post

    Thanks Moloko_man and also Willr, got this working

    1110 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.