Custom member login page

Silverstripe Version:4.0.3

Question: What is the cleanest way to make a custom member login page?

Just wanted to alter the login page for members so I can;

  • change the layout
  • add custom JavaScript (specifically to show a splash image before the login form)
  • add to the form fields and validate them ( specifically a checkbox agreeing to the t&c)

I have managed to achieve the first two of these points by adding a file to my site modules templates/Layout folder.
Then adding the java script file in this way;

<% require css("kiwi/code/css/SplashLogin.css") %>

Then I tried to extend SilverStripe\Security\MemberAuthenticator\MemberLoginForm
like so;

use SilverStripe\Security\MemberAuthenticator\MemberLoginForm;
class CustomMemberLogin extends MemberLoginForm{
        private static $required_fields = [
    function getFormFields(){
        $fields = parent::getFormFields();
                    "Agree To Terms"

But then when I added this to a yml config (app.yml) it went a little haywire:

    class: CustomMemberLogin

After that I was unable to load the login page or see any errors.

Is there a cleaner and easier method entirely and/or have I missed something crucial?

As I was driving to work this morning I suddenly had a though; "did I return $fields from getFormFields()?

The answer was no.

So adding;
return $fields; to the end of the getFormFields() method
fixed this!

I’m still curious if this is the best approach so please reply if you have any insight!

1 Like