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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Extending the Login Form

Go to End



Community Member, 102 Posts

25 March 2010 at 8:43pm


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.