Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

[solved] Edit Member Profile Page Not Writing to Member


Reply


4 Posts   1584 Views

Avatar
zenmonkey

Community Member, 528 Posts

29 September 2009 at 6:50am

Edited: 30/09/2009 1:55am

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

Avatar
Dave L

Community Member, 57 Posts

29 September 2009 at 11:32pm

At a glance...

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

?

Is ChangePersonalDetails getting called?

Avatar
zenmonkey

Community Member, 528 Posts

30 September 2009 at 1:56am

Wow Coding before Caffeine not a good idea. LOL Thanks

Avatar
arferrari

Community Member, 4 Posts

3 December 2010 at 11:09am

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