Jump to:

1030 Posts in 805 Topics by 311 members

Forum Module

SilverStripe Forums » Forum Module » Customizing the forum registration form

Discuss the Forum Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1351 Views
  • Yokelassence
    Avatar
    Community Member
    15 Posts

    Customizing the forum registration form Link to this post

    Hi guys, just looking for simple advice here.

    I have an existing registration form on my website that records some personal details and some misc details of their own choosing.

    I want to integrate my existing registration form with the forum module registration form so that when users register with the website, they also get a forum account at the same time.

    So either I extend the forum registration form to include the other details I need, or I make my existing registration form create it's own forum user objects

    Where should I begin and what sort of things should I be aware of before modifying the forum module registration form?

    I know that the forum registration code is inside ForumMemberProfile.php, can I just append to this without consequence?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Customizing the forum registration form Link to this post

    Create a DataExtension (or DataObjectDecorator in SS2.4) and apply it to the Member base class.

    You can then modify the registration form using the extension hook updateForumFields.

  • facon12
    Avatar
    Community Member
    2 Posts

    Re: Customizing the forum registration form Link to this post

    Is there documentation anywhere on the Forum module other than: https://github.com/silverstripe/silverstripe-forum. The documentation there is pretty lacking for knowing what hooks and functions to use to extend the module. I realize i could read through the code in the module but it seems like this would be documented in an api or something along those lines. I get the impression from other posts that the forum module had more documentation for previous versions of silverstripe.

  • Yokelassence
    Avatar
    Community Member
    15 Posts

    Re: Customizing the forum registration form Link to this post

    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

    1351 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.