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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

Multiform module - DateField using 'now' - SS3

Go to End



Community Member, 165 Posts

25 May 2013 at 4:24am

Hi there,

Some time ago I used the multiform module for a client on SS2.4.7 I have just upgraded to SS3 and reworked the code for my multiform to comply. Works great except for I can't seem to figure out how to populate my datefield with todays date. I'm using the populateDefaults method.

Here is my new code:


class CallEvent extends DataObject{

	static $db = array(
		'CallerFirstName' => 'Text',
		'CallerSurname' => 'Text',
		'CallerRelationship' => 'Text',
		'CallerPhone' => 'Text',
		'CallerExt' => 'Text',
		'CallerEmail' => 'Text',
		'DateOfCall' => 'SS_Datetime',
		'TimeOfCall' => 'Time',
		'TotalNumberOfCalls' => 'Text',
		'CallerStatusOther' => 'Text',
		'PaperCopy' => 'Text',
		'DetailsOfEnquiry' => 'HTMLText',
		'ContactIn' => 'Text',
		'ContactOut' => 'Text',
		'TotalWebSearches' => 'Text',
		'HubContact' => 'Text',
        public function populateDefaults(){
		$this->DateOfCall = date('Y-m-d H:i:s', strtotime('now'));

$dateofcall = new DateField("DateOfCall", "Date of first call");
	$dateofcall->setConfig('showcalendar', true);
	$dateofcall->setConfig('dateformat', 'dd/MM/YYYY');

public function getFrontendFields($params = null){
	$fields = $this->scaffoldFormFields(array(
		'restrictFields' => array(
		'fieldClasses' => array(
			'CallerFirstName' => 'TextField',
			'CallerSurname' => 'TextField',
			'CallerRelationship' => 'TextField',
			'CallerPhone' => 'TextField',
			'CallerExt' => 'TextField',
			'CallerEmail' => 'EmailField',
			'DateOfCall' => 'DateField',
			'TimeOfCall' => 'TimeField',
			'TotalNumberOfCalls' => 'NumericField',
			'CallerStatusOther' => 'TextField',
			'PaperCopy' => 'CheckboxField',
			'DetailsOfEnquiry' => 'HtmlEditorField',
			'ContactIn' => 'NumericField',
			'ContactOut' => 'NumericField',
			'TotalWebSearches' => 'NumericField',
			'HubContact' => 'TextField',

	$fields->push( new TextField("CallerFirstName", "Callers first name"));
	$fields->push( new TextField("CallerSurname", "Callers surname"));
	$fields->push( new TextField("CallerRelationship", "Callers relationship to person"));
	$fields->push( new TextField("CallerPhone", "Callers phone number"));
	$fields->push( new TextField("CallerExt", "Callers extension number"));
	$fields->push( new EmailField("CallerEmail", "Callers email address"));
        $fields->push( $dateofcall );

From all the documentation and tutorials I have researched this looks as though it should work. Any help here is greatly appreciated. Thanks