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'