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.

All other Modules

Discuss all other Modules here.

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

Register Module - Improvements


Reply

4 Posts   2800 Views

Avatar
chrisdarl

13 June 2009 at 10:18am Community Member, 33 Posts

I've made the following changes to my copy of the Registration module [unreleased] which Sam may want to add..

In RegisterPage_Controller class add
   
   function init() {
      parent::init();
      
      if(!$usersGroup = DataObject::get_one("Group", "Code = 'users'")) {
         $group = new Group();
         $group->Code = 'users';
         $group->Title = "Users";
         $group->write();
      }
   }

Replace Form() method with :
/**
    * Return the edit form for the current user
    */
   function Form() {
      // Get the fields from a new member - seems like a good default :-)
      $member = new Member();
      $fields = $member->getMemberFormFields();
      $fields->replaceField('Password', new PasswordField('Password') );
      $actions = new FieldSet(
         new FormAction('register', 'Register')
      );

      $form = new Form(
         $this,
         'Form',
         $fields,
         $actions,
         new RequiredFields("FirstName", "Surname", "Email", "Password")
      );

      return $form;
   }

this then gives a password field rather than a text field, and adds a validator

Replace register() method with :
   /**
    * Save the profile details
    */
   function register($data, $form) {
      // Create a new member and save the form into it
      $member = new Member();
      $form->saveInto($member);
      
      // Write to the databsae
      $member->write();
      
      $groupMember = new Group();
      $groupMember->addToGroupByName($member, 'users');
      
      // To do: add a status message on the form, using the standard form message system

      // Return to the original form
      Director::redirect($this->Link() . 'thanks');
   }

This adds the new Member to the Group we created in init() -- 'users'

Avatar
rpw2

14 June 2009 at 9:58pm Community Member, 6 Posts

Hi there, thanks for the updates and it works as you'd expect. I have a question tho, if I was wanting to capture additional member data, ie. Phone, Address details, City, Country ect. What is the way to achieve this? is it possible to have this data in a different table to member or just add extra fields to existing member table? thanks.

Avatar
Willr

14 June 2009 at 10:10pm Forum Moderator, 5511 Posts

chrisdarl - if you want to suggest code changes to the modules please use open.silverstripe.com and submit the change as a patch / diff file so we can merge it into the module :) otherwise it just sits round on the forum for years.

When you make your ticket on open.silverstripe.com please ensure you list the changes you made and why and tag it with the correct component / tags.

Avatar
rpw2

18 June 2009 at 1:55pm Community Member, 6 Posts

More clues here;

http://www.silverstripe.org/customising-the-cms/show/251406#post251406

and here (this link is at bottom of above post);

this tutorial may be useful for you :
http://www.ssbits.com/custom-login-form-with-group-based-redirection/

Also, in one of the tutorials in suggests, if you want to just grab peoples details and not give them any 'logged in' capabilities, then don't register them (with a password) in the core members table.
The Forum module is perfect for seeing how to extend the current member table, if you do need to do it tho.