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.

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


909 Views

Avatar
Harley

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:

CallEvent.php

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(){
		parent::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(
			'CallerFirstName',
			'CallerSurname',
			'CallerRelationship',
			'CallerPhone',
			'CallerExt',
			'CallerEmail',
			'DateOfCall',
			'TimeOfCall',
			'TotalNumberOfCalls',
			'CallerStatusOther',
			'PaperCopy',
			'DetailsOfEnquiry',
			'ContactIn',
			'ContactOut',
			'TotalWebSearches',
			'HubContact',
		),
		'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

Regards