Jump to:

23376 Posts in 18214 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Update Page Information on Front End

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: 1091 Views
  • Media Contour
    Avatar
    Community Member
    33 Posts

    Update Page Information on Front End Link to this post

    I have created Profile Pages that have a Member assigned to them.

    class ProfilePage extends Page {
       static $db = array(
          'MemberName' => 'Varchar(255)'
       );
       
       static $has_one = array(
          'Member' => 'Member'
       );
       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $memberfield = new HasOneDataObjectManager(
             $this,
             'Member',
             'Member',
             array(
                'FirstName' => 'First Name',
                'Surname' => 'Last Name',
                'Email' => 'Email'
             ),
             'getCMSFields_forPopup'
          );
          $fields->addFieldToTab('Root.Content.Member', $memberfield);
          
          return $fields;
       }
    }

    class EditProfilePage_Controller extends Page_Controller {}

    I also created an Edit Profile Page that has a form. Now what I want to be able to do is when the signed in member fills out the form and hits submit the form update the Profile Page who's "MemberID" matches that of the Member's "ID". How do I do that? I can't seem to figure it out.

    class EditProfilePage extends Page {}

    class EditProfilePage_Controller extends Page_Controller {
       
       public function init() {
          parent::init();
       }

       function EditProfile() {
          $fields = new FieldSet(
             new TextField('BandName', 'Band Name')
          );
          $actions = new FieldSet(new FormAction("UpdateProfile", "Update"));
          return new Form($this, "EditProfile", $fields, $actions);
       }
       
       function UpdateProfile($data, $form) {
          // ?????
       }
    }

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: Update Page Information on Front End Link to this post

    Hi!

    I’ve never done it myself, but looking at the registration module today I found an EditDetailsPage that could help you: http://silverstripe.org/registration-module/

  • carlos
    Avatar
    Community Member
    41 Posts

    Re: Update Page Information on Front End Link to this post

    hi

    you need to add member id to the form, so you know what member to update.

    ...
    new HiddenField('memberID','',$thisMemberID);
    ...

    now you need to update the member.

    //find member
    $member=DataObject::get_by_id('Member',$data['memberID']);
    if($member){
    $member->BandName = $data['BandName'];
    $member->write();
    }

    hope it helps
    cheers

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