Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Has anyone created a user profile page successfully?

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

Page: 1
Go to End
Author Topic: 2107 Views
  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Has anyone created a user profile page successfully? Link to this post

    Has anyone created a user profile page successfully? With information editing capability in particular. Updating password would be the most important one.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Has anyone created a user profile page successfully? Link to this post

    Have a look at the forum module - this has this capability.

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Has anyone created a user profile page successfully? Link to this post

    SilverStripe has a standard change password form that you can use. There's a form called ChangePasswordForm that you can just plug right in without having to do any modifications.

    I use it like this

       public function ChangePassword() {
          return new ChangePasswordForm($this, 'ChangePassword');
       }


    That goes in the controller of your choice (I don't know if you can put it in the model as well) and then you just type $ChangePassword in your template to output the form.

    All the behind the scenes mojo is taken care of so you don't have to worry about it.

    When it comes to the user profile page I rolled my own.

    It looks like this

       function ContactForm() {
          $member = $this->CurrentMember();
          //var_dump($member);
    // Create fields
    $fields = new FieldSet(
    new TextField('FirstName', 'First Name*', $member->FirstName),
    new TextField('LastName', 'Last Name*', $member->Surname),
    new TextField('Email', 'Email (User Name)*', $member->Email)
    );

    // Create action
    $actions = new FieldSet(
    new FormAction('ChangePersonalDetails', 'Change')
    );

    // Create Validators
    $validator = new RequiredFields('FirstName', 'LastName', 'Email');

    return new Form($this, 'ContactForm', $fields, $actions, $validator);
    }

    And then this to save

       function ChangePersonalDetails($data) {

          $member = $this->CurrentMember();
          $member->FirstName = $data['FirstName'];   
          $member->Surname = $data['LastName'];
          $member->Email = $data['Email'];
          $member->write();

    //return to submitted message
    Director::redirect(Director::baseURL(). $this->URLSegment);
    }


    I bet it can be done alot more robustly but this should get you started.

    Kindly,
    Marcus

  • Lucas
    Avatar
    Community Member
    10 Posts

    Re: Has anyone created a user profile page successfully? Link to this post

    Andrew Short has done so, and it's a very full-featured module.

    See here: http://github.com/ajshort/silverstripe-memberprofiles

    - L

    2107 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.