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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

[solved] Newsletter subscription error on existing user email

Go to End

4 Posts   1043 Views


Community Member, 56 Posts

10 February 2012 at 4:31am

Hi everybody.

On bugfixin our latest project we discovered a strange newsletter subscription error. On the homepage there is a form saving all subscribers as a new member in the db. if a mailadress is already saved – no matter whether teh user is an admin or in another usergroup – a exception is thrwon.

throw new ValidationException(new ValidationResult(false, sprintf(
629 _t(
630 'Member.ValidationIdentifierFailed',
631 'Can\'t overwrite existing member #%d with identical identifier (%s = %s))',
633 'The values in brackets show a fieldname mapped to a value, usually denoting an existing email address'
634 ),

The code on Homepage.php

// Make sure you set this to the right group.
	// See
	private $defaultGroupID = 3;
	* This function lets you put a form on your page, using $Form.
	 function NewsletterForm() {
		return new Form($this, "NewsletterForm", new FieldSet(
			// List your fields here
			new TextField("Surname", "Name"),
			new EmailField("Email", "E-Mail")
		), new FieldSet(
			// List the action buttons here
			new FormAction("SignupAction", "Eintragen")
		), new RequiredFields(

	* This function is called when the user submits the form.
	function SignupAction($data, $form) {
		// Create a new Member object and load the form data into it
		$member = new Member();
		// Write it to the database.  This needs to happen before we add it to a group
		// Add the member to group. (Check if it exists first)
		if($group = DataObject::get_one('Group', "ID = $this->defaultGroupID")) { 
			// Redirect to a page thanking people for registering
			// Redirect to a failure page

$defaultGroupID = 3 is the newsletter user group created in the security section of the cms.
Why does the Director::redirect('newsletter-registristrierungs-fehler/'); not work?
What to edit on this code to catch this error?

Thanks. Pipifix

Silverstripe 2.46


Community Member, 344 Posts

10 February 2012 at 5:09am

What to edit on this code to catch this error?

You will need to validate the mailadress yourself. Silverstripe will just throw the error, because double user identifier is a bad thing.

Why does the Director::redirect('newsletter-registristrierungs-fehler/'); not work?

Because you check in your if clause if a group with the ID 3 exists. Which of course is always the case since you created it.


Community Member, 56 Posts

10 February 2012 at 6:38am

Thanks Devlin.

The double user issue was clear. See the thread headline ;) The second things was too obviously. ^^
You're right. This condition is always true. My problem is i'm a php-noob. I need a lot more programming exercise to write creative and useful code. The most of the code provided here, im able to read and understand. Thats why i ask for a little coding help.

I found this snippet of code and tried to adapt it. This checkt the user and sanitize the mailadress. But this piece dont write in the usergroup and the redirection is something weird. (404) I like the idea to set the NewsletterSubscriber as a 'quiet' user and redirect them to a sucess-page or a failure-page. No login should be seen.

Thanks again. Pipifix.


Community Member, 56 Posts

14 February 2012 at 7:05am


Hello verybody , hello Devlin.

I found a snippet/tutorial that do exactly what i want so i wana share this with you.

happy coding. Pipifix