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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

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

So how does a new user register?


Go to End


17 Posts   55207 Views

Avatar
Sean

Forum Moderator, 922 Posts

7 October 2008 at 11:42am

Edited: 07/10/2008 11:53am

Member::create_new_password() will generate a password.

So, you could do something like this, which takes the form data and puts it into a new member instance. This is the submit handler for the doForm action for where you setup your form, which would look something like:


class RegistrationForm extends Form {

	function __construct($controller, $name) {

		$fields = new FieldSet(
			new TextField('FirstName', 'First name'),
			new EmailField('Email', 'Email address')
		);

		$actions = new FieldSet(
			new FormAction('doForm', 'Submit')
		);

		$validator = new RequiredFields(
			'FirstName',
			'Email'
		);

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

	function doForm($data, $form) {

		// Create a new member instance, loading all the form data in
		$member = new Member();
		$form->saveInto($member);

		// Set the member password and write with all the form data collected to DB
		$member->Password = Member::create_new_password();
		$member->write();

		$form->sessionMessage('Thanks, you have been signed up!', 'good');
		Director::redirectBack();
	}

}

Hope that helps.

Generally a module would be great, although it would need to be fairly abstract to allow for all combination of fields that a user can sign up with.

Sean

Go to Top