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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Automatically insert current date into date field of new pages


Go to End


2 Posts   2542 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, 344 Posts

28 July 2010 at 7:24pm

Edited: 28/07/2010 7:25pm

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

http://doc.silverstripe.org/recipes:populatedefaults