Faloude Faloude - 1 year ago 154
PHP Question

SilverStripe login form customisation

What's the easiest way to customise the default silverstripe login form? My final goal is to apply

to the login action button.

Answer Source

In SilverStripe 3.4 we can extend MemberLoginForm, set the action in our constructor and then set SilverStripe to use the custom log in class as the default log in class.

First we create a CustomMemberLoginForm class:


class CustomMemberLoginForm extends MemberLoginForm {

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

        $actions = FieldList::create(
            FormAction::create('dologin', _t('Member.BUTTONLOGIN', 'Log in'))->addExtraClass('myClass'),
                '<p id="ForgotPassword"><a href="Security/lostpassword">'
                . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'

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

In our mysite/_config.php we add the following code to tell SilverStripe to use our custom log in class:


Object::useCustomClass('MemberLoginForm', 'CustomMemberLoginForm');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download