How do we set today's date to be populated by default on a Date field when page loads?
Here is what I Tried:
static $defaults = array(
'GameDate' => 'date(\'Y-m-d\')'
);
public function GameResultForm() {
$gameDate = new DateField('GameDate');
$gameDate->setConfig('showcalendar', true);
$gameDate->setConfig('dateformat', 'dd-MM-YYYY');
$gameDate->setConfig('max', date('Y-m-d'));
$fields = new FieldList (
$gameDate
);
$actions = new FieldList(
new FormAction('saveNewGame', 'Add New Game')
);
$form = new Form($this, 'GameResultForm', $fields, $actions,);
$form->setFormMethod('POST', true);
$data = Session::get("FormData.{$form->getName()}.data");
return $data ? $form->loadDataFrom($data) : $form;
I also tried
$gameDate->setConfig('setValue', date('Y-m-d'));