Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Updating page data from form on front-end

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

Page: 1
Go to End
Author Topic: 1474 Views
  • dynamite
    Avatar
    Community Member
    66 Posts

    Updating page data from form on front-end Link to this post

    Hello! This may be a very "noob-ish" question, but I have been unable to find a similar scenario in the tutorials, documentation or forums.

    I have a form set up on the "FacultyProfile" pages when the logged in member matches, so that they can edit a little mini-profile. When I save/write the data, it seems to update okay (no errors, and when I refresh, the changes appear on the front end). However, when going in to the CMS, the changes are not reflected in there.

    class FacultyProfile extends Page {
    static $db = array(
       'LastName' => 'Text',
       'FirstName' => 'Text',
       'YourTitle' => 'Text',
       'E-MailAddress' => 'Text',
       'WebSite' => 'Text'
    );

       function getCMSFields()
       {

          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Main', new TextField('LastName'), 'Content');
          $fields->addFieldToTab('Root.Content.Main', new TextField('FirstName'), 'Content');
          $fields->addFieldToTab('Root.Content.Main', new TextField('YourTitle'), 'Content');
          $fields->addFieldToTab('Root.Content.Main', new TextField('E-MailAddress'), 'Content');
          $fields->addFieldToTab('Root.Content.Main', new TextField('WebSite'), 'Content');
          return $fields;
       }
       
    }

    class FacultyProfile_Controller extends Page_Controller {

    // i removed the other methods that are working already

       function SaveProfile($data, $form) {
          $form->saveInto($this);
          $this->write();
          Director::redirect('profile-updated');
       }
       
    }

  • dynamite
    Avatar
    Community Member
    66 Posts

    Re: Updating page data from form on front-end Link to this post

    *bump*

    Any ideas? I am quite stymied!

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Updating page data from form on front-end Link to this post

    did you run a /db/build?flush=1

    and try refreshing your browser

  • dynamite
    Avatar
    Community Member
    66 Posts

    Re: Updating page data from form on front-end Link to this post

    Thanks for the reply... but no, neither of those help.

    After some further poking around, I found that if I pull up the page in the CMS and open the Page Version History and check the box labeled "Show Unpublished Versions", the changes are in there!

    So I guess my question is, what function do I run to "publish" a page?

    Thanks again.

  • dynamite
    Avatar
    Community Member
    66 Posts

    Re: Updating page data from form on front-end Link to this post

    Found in another thread, and tested and it works now! I changed

    $this->write();


          
    to

    $this->writeToStage('Stage');
    $this->publish('Stage','Live');

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Updating page data from form on front-end Link to this post

    I am also working on similar Dept settings but at this moment we did not test updating own profiles. BTW, one can always limit the access to all pages to selected group (Admins and Editors) and then allow to certain members edit their pages (see Access pane)

    However we decided to have more fields

    class FacultyPage extends Page {
    static $db = array(
    'lastname' => 'Text',
    'firstname' => 'Text',
    'middlename' => 'Text',
    'email' => 'Text',
    'website'=> 'Text',
    'position' => 'Text',
    'position2'=> 'Text',
    'honors' => 'Text',
    'officesg' => 'Text',//Multiple campuses and some people have 2 offices
    'officesc' => 'Text',
    'officems' => 'Text',
    'phone' => 'Text',
    'phone2' => 'Text',
    'interests' => 'Text',
    );

    where position1 is described by DropDown

    $fields->addFieldToTab("Root.Content.Main", new DropdownField("position", "position",
    array( 'Professor'=>'Professor',
    'Associate Professor'=>'Associate Professor',
    'Assistant Professor'=>'Assistant Professor',
    'PostdoctoctoralFellow'=>'PostdoctoctoralFellow',
    'Professor Emeritus'=>'Professor Emeritus',
    'University Professor'=>'University Professor',
    'Senior Lecturer'=>'Senior Lecturer',
    'Lecturer'=>'Lecturer',
    'Assistant Professor - CLTA'=>'Assistant Professor - CLTA')
    ),'Content');


    while position2 is for unique like Chair,... so in FacultyPage.ss piece of code is

    $position<% if position2 %>, <% end_if %>$position2<% if honors %>, <% end_if %> $honors

    to produce variants like this

    Professor
    Professor, Chair
    Professor, FRSC
    Professor, Chair, FRSC

    PS Since we are doing the same thing we can have already solutions useful for one another. If intetested, drop email vivrii@gmail.com

    Victor

    PPS Currently we are not ready to upload module, but when finish will surely do
    We are ready to share our current work with other University Departments now

    People (Faculty,Staff,Students)
    Seminars

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