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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Updating page data from form on front-end


Go to End


6 Posts   2917 Views

Avatar
dynamite

Community Member, 66 Posts

28 March 2009 at 6:09am

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');
	}
	
}

Avatar
dynamite

Community Member, 66 Posts

31 March 2009 at 8:11am

*bump*

Any ideas? I am quite stymied!

Avatar
Nivanka

Community Member, 400 Posts

31 March 2009 at 11:53pm

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

and try refreshing your browser

Avatar
dynamite

Community Member, 66 Posts

1 April 2009 at 2:31am

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.

Avatar
dynamite

Community Member, 66 Posts

1 April 2009 at 2:46am

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

$this->write();

to

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

Avatar
Victor

Community Member, 128 Posts

1 April 2009 at 9:37pm

Edited: 02/04/2009 5:33am

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