Jump to:

10998 Posts in 2732 Topics by 1822 members

All other Modules

SilverStripe Forums » All other Modules » Multiform module - DateField using 'now' - SS3

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 399 Views
  • Harley
    Community Member
    153 Posts

    Multiform module - DateField using 'now' - SS3 Link to this post

    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


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.