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

Automatically insert current date into date field of new pages


Reply


2 Posts   1497 Views

Avatar
DeklinKelly

Community Member, 197 Posts

28 July 2010 at 12:47pm

I use the following code in conjunction with the legacydatetimefields module to allow the administrator to select a date:

$fields->addFieldToTab("Root.Content.Times", new PopupDateTimeField('RankingDate', 'Ranking Date'));

When a page is create that field is blank. I want the current date to be placed in that field when new pages are created but after the page is created I want the administrator to be able to change it to any date.

Avatar
Devlin

Community Member, 215 Posts

28 July 2010 at 7:24pm

Edited: 28/07/2010 7:25pm

public function populateDefaults(){
   $this->RankingDate = date("Y-m-d");
}

[url]http://doc.silverstripe.org/recipes:populatedefaults[/url]