Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » Customising member login form

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

Page: 1
Go to End
Author Topic: 1591 Views
  • Scorpiankh
    Avatar
    Community Member
    60 Posts

    Customising member login form Link to this post

    Hi. I'm trying to find a way to customise the login bit for members-only pages on a website I'm building.
    What I want to do is this:
    - change the 'email' label on login to 'username'
    - remove the 'lost password' link
    - add a link for 'change password' that gets displayed once a user is logged in.

    I tried changing the 'email' label to 'username' in sapphire/security/MemberLoginForm.php but all I managed to do was make the login form not work at all.
    As far as I can tell all the code for the things I want to do is in MemberLoginForm.php but I'm not sure which bits exactly to edit, I'm still pretty new to php, still getting the hang of it.
    Can anyone tell me how to go about making the login form work how i want it?

    Thanks

  • rob.s
    Avatar
    Community Member
    78 Posts

    Re: Customising member login form Link to this post

    Hi,

    perhaps the following helps.

    create a custom class that extends MemberLoginForm :

    For example:

    class MyCustomLoginForm extends MemberLoginForm {

    public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true) {

    $label=singleton('Member')->fieldLabel(Member::get_unique_identifier_field());
    $fields = new FieldSet(
    new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this),
    //Regardless of what the unique identifer field is (usually 'Email'), it will be held in the 'Email' value, below:
    new TextField("Email", $label, Session::get('SessionForms.MemberLoginForm.Email'), null, $this),
    new PasswordField("Password", _t('Member.PASSWORD', 'Password'))
    );
    if(Security::$autologin_enabled) {
    $fields->push(new CheckboxField(
    "Remember",
    _t('Member.REMEMBERME', "Remember me next time?")
    ));
    }

    parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
    }

    }

    you can add custom fields to the fieldset .....

    then put into your _config.php

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

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