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))',
632 PR_MEDIUM,
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 http://doc.silverstripe.com/doku.php?do=show&id=recipes%3Aforms
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(
'Email',
'Surname'
));
}
/**
* 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();
$form->saveInto($member);
// Write it to the database. This needs to happen before we add it to a group
$member->write();
// Add the member to group. (Check if it exists first)
if($group = DataObject::get_one('Group', "ID = $this->defaultGroupID")) {
$member->Groups()->add($group);
// Redirect to a page thanking people for registering
Director::redirect('newsletter-erfolgreich-eingetragen/');
}else{
// Redirect to a failure page
Director::redirect('newsletter-registristrierungs-fehler/');
}
}
$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