Hello again, bumping an old topic I know. But I figured I should give you my results
So I decided not to mess with the original registration form for the forum. I have left it as is in order to avoid creating more problems in the long term. Instead I focused on adding the necessary code to my own registration form so that it has the power to create an object of the Member class
In my own registration form I copied the code from the forum function called doregister which is inside the file called ForumMemberProfile.php and added that to my own code
The key part you need is this:
$forumGroup = DataObject::get_one('Group', "Code = 'forum-members'");
if ($member = DataObject::get_one("Member", "`Email` = '" . Convert::raw2sql($data['email']) . "'")) {
if ($member) {
$form->addErrorMessage("Blurb",
_t('ForumMemberProfile.EMAILEXISTS', 'Sorry, that email address already exists. Please choose another.'),
"bad");
// Load errors into session and post back
Session::set("FormInfo.Form_RegistrationForm.data", $data);
Director::redirectBack();
return;
}
} elseif ($this->OpenIDAvailable() && ($member = DataObject::get_one("Member",
"`IdentityURL` = '" . Convert::raw2sql($data['IdentityURL']) . "'"))) {
if ($member) {
$form->addErrorMessage("Blurb",
_t('ForumMemberProfile.OPENIDEXISTS', 'Sorry, that OpenID is already registered. Please choose another or register without OpenID.'),
"bad");
// Load errors into session and post back
Session::set("FormInfo.Form_RegistrationForm.data", $data);
Director::redirectBack();
return;
}
} elseif ($member = DataObject::get_one("Member",
"`Nickname` = '" . Convert::raw2sql($data['Nickname']) . "'")) {
if ($member) {
$form->addErrorMessage("Blurb",
_t('ForumMemberProfile.NICKNAMEEXISTS', 'Sorry, that nickname already exists. Please choose another.'),
"bad");
// Load errors into session and post back
Session::set("FormInfo.Form_RegistrationForm.data", $data);
Director::redirectBack();
return;
}
}
$member = Object::create('Member');
$member->Nickname = $data['Nickname'];
$member->Firstname = $data['Firstname '];
$member->Surname = $data['Surname '];
$member->Occupation = $data['Occupation '];
$member->Company = $data['Company '];
$member->City = $data['City '];
$member->Country = $data['Country '];
$member->Email = $data['Email '];
$member->write();
$member->login();
$forumGroup->Members()->add($member);
I love how I can call such classes from anywhere within Silverstripe. This works just fine outside of the original forum code so long as my registration form still carries the expected database fields (This is all inside $data)
With that together with all the other dependent code snippets from ForumMemberProfile.php tucked away inside my controller it worked like a charm. Whenever customers sign up with the website they automatically get a forum account with their subscription
BUT I should also add that I did this before I saw Willr's comment
Now having seen Willr's comment, I'm going to suggest that instead. I haven't played with DataObjectDecorator before (nice example here) so it did not cross my mind but that would be the correct way of extending the forum's registration form with new fields.
My method dodges around the problem rather than addresses it, although it does give me my own form which I have full control over