Jump to:

23478 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Get member by email address

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: 1282 Views
  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    Get member by email address Link to this post

    I can get the current member like this:

    $member = Member::currentUser();

    How can I get a member by email address? This does NOT work:

    $member = Member::GetUserByEmail('user@example.com');

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Get member by email address Link to this post

    What about:

    $m = DataObject::get_one('Member',"Email ='".$someEmailAddress."'");

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: Get member by email address Link to this post

    Also better make sure $someEmailAddress is SQL safe as well as SS won't do this magically for you. If $someEmailAddress is a user input (like a form) you should do $someEmailAddress = Convert::raw2sql($someEmailAddress); before the dataobject get line.

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Get member by email address Link to this post

    True, didn't thought of a userinput case.

  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    Re: Get member by email address Link to this post

    Thanks. But I can't seem to use this the same way I use Member::

       $member = DataObject::get_one("Member", "`Email` = 'xyz@example.com'");
       $member->CustomField = 'Hello';
       $member->write();

    I am trying to change the value of CustomField to "Hello".

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: Get member by email address Link to this post

    That is the correct way, write() should save it to the database. Does it not update the member table? How have you added that CustomField to the database (eg via a decorator?)

    1282 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.