Jump to:

23552 Posts in 19349 Topics by 2891 members

General Questions

SilverStripe Forums » General Questions » Extending the Login Form

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: 1199 Views
  • patjnr
    Community Member
    101 Posts

    Extending the Login Form Link to this post


    the default LoginForm has two(2) text fileds

    1. EMAIL ...................................
    2. PASSWORD ..................................

    Now i want to extend this by adding one or two more text fields basically for the sake of validation. eg like adding a third field for Recapture since the form will be on every page of the site.

    after login user have to be redirected to their respective page with relevant content.

    i am using CustomeLogin form and the here is the code


    class CustomLogin extends MemberLoginForm {

       // this function is overloaded on our sublcass (this) to do something different
       public function dologin($data) {
          if($this->performLogin($data)) {
                //echo 'done';
          } else {
             if($badLoginURL = Session::get("BadLoginURL")) {
             } else {

       public function redirectByGroup($data) {    

          // gets the current member that is logging in.
          $member = Member::currentUser();
          // gets all the groups.
          $Groups = DataObject::get("Group");
          //cycle through each group   
          foreach($Groups as $Group){
             //if the member is in the group and that group has GoToAdmin checked
             if($member->inGroup($Group->ID) && $Group->GoToAdmin == 1)
                //redirect to the admin page
                 Director::redirect(Director::baseURL() . 'admin' );
                return true;
             //otherwise if the member is in the group and that group has a page link defined
             elseif($member->inGroup($Group->ID) && $Group->LinkPageID != 0)
                //Get the page that is referenced in the group      
                $Link = DataObject::get_by_id("SiteTree", "{$Group->LinkPageID}")->URLSegment;
                //direct to that page
                Director::redirect(Director::baseURL() . $Link);
                return true;
          //otherwise if none of the above worked return false
          return false;

    _congif.php i add these lines

    Object::useCustomClass('MemberLoginForm', 'CustomLogin');

    //Tells silverstripe to add our extention to the group class
    Object::add_extension('Group', 'GroupDecorator');

    in the CMS i just create more Groups and specify which pages they go after log in.

    The above code is work but it is limited to what i want.



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.