Jump to:

23355 Posts in 17838 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » [solved] Edit Member Profile Page Not Writing to Member

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1532 Views
  • zenmonkey
    Avatar
    Community Member
    527 Posts

    [solved] Edit Member Profile Page Not Writing to Member Link to this post

    I'm trying to create a Page where Members can edit their own profile, but the form doesn't seem to be writing back to the member table.

    function UserProfileForm()
       {
          //Get Current Member Info
          $member = $this->CurrentMember();
          
          
          //Create Form
          $fields = new FieldSet(
                          new FieldGroup (
                                      new HeaderField('Personal Information', 3),
                                      new TextField('FirstName', 'First Name', $member->FirstName),
                                      new TextField('Surname','Last Name', $member->Surname ),
                                      new EmailField('Email','Email', $member->Email)
                                      ),
                          new FieldGroup (
                                      new HeaderField('Company Information', 3),
                                      new TextField('CompanyName','Company Name', $member->CompanyName),
                                      new TextField('CompanyURL','Company Website', $member->CompanyURL),
                                      new TextField('HomePhone','Company Phone', $member->HomePhone),
                                      new TextField('Address','Address', $member->Address),
                                      new TextField('AddressLine2','Address Line 2', $member->AddressLine2),
                                      new TextField('City','City', $member->City),
                                      new TextField('State','State or Province', $member->State),
                                      new TextField('Country','Country', $member->Country)
                                      )
                          );
          $fields->push(new HiddenField("ID"));
          
          $actions = new FieldSet(
                            new FormAction('ChangePersonalDetails', 'Update Profile')
                            );
          
          // Create Validators
          $validator = new RequiredFields('FirstName', 'LastName', 'Email');
          
          return new Form($this, 'ContactForm', $fields, $actions, $validator);
       }
          
       function ChangePersonalDetails($data,$form)
       {
          
          $member = $this->CurrentMember();
          $member->FirstName = $data['FirstName'];
          $member->Surname = $data['LastName'];
          $member->Email = $data['Email'];
          $member->CompanyName = $data['ComapnyName'];
          $member->CompanyURL = $data['CompanyURL'];
          $member->HomePhone = $data['HomePhone'];
          $member->Address = $data['Address'];
          $member->AddressLine2 = $data['AddressLine2'];
          $member->City = $data['City'];
          $member->State = $data['State'];
          $member->Country = $data['Country'];
          $member->companyTypeList = $data['companyTypeList'];
          
          
          $member->write();
          
          Director::redirect(Director::baseURL(). $this->URLSegment);
       }

    Any Suggestions? The

  • Dave L
    Avatar
    Community Member
    56 Posts

    Re: [solved] Edit Member Profile Page Not Writing to Member Link to this post

    At a glance...

    return new Form($this, 'ContactForm', $fields, $actions, $validator);
    ->>
    return new Form($this, 'UserProfileForm', $fields, $actions, $validator);

    ?

    Is ChangePersonalDetails getting called?

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: [solved] Edit Member Profile Page Not Writing to Member Link to this post

    Wow Coding before Caffeine not a good idea. LOL Thanks

  • arferrari
    Avatar
    Community Member
    4 Posts

    Re: [solved] Edit Member Profile Page Not Writing to Member Link to this post

    I Know that is an old topic but for newbies in SS (like me =)) this module is very useful

    https://github.com/ajshort/silverstripe-memberprofiles

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