Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions

Customising member login form


Reply

2 Posts   1657 Views

Avatar
Scorpiankh

15 November 2010 at 5:45pm Community Member, 60 Posts

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

Avatar
rob.s

16 November 2010 at 6:06am Community Member, 78 Posts

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');