Get the date/time of a front end form submission

SS4

I am trying to add a timestamp to form submissions written to the DB, using pointers from this thread.

Is there a built in method on a form object to get the date/time of the submission?

I am trying to manually set a form hiddenfield’s value in the FormAction, but cannot make it work…


//setting the date at creation works,
// however, I would prefer the timestamp to be when the submit handler fires
HiddenField::create('Date')->setValue(DBDatetime::now());

//I have tried the following methods in the FormAction, without success
public function submit($data, $form) {

//...

 $form->setField('Date', DBDatetime::now());

 $form->Fields()->getField('Date')->setValue(DBDatetime::now());

 $submission = Contact::create();
 $form->saveInto($submission);
 $submission->write();
//...

}

Cheers,
Olly

You should be able to get the date the dataobject $submission was written from it’s Created property. ie $Submission->Created.

Thanks @MilesSummers!

just wonderung how the sourcecode looks like, do you have an example? cant get it to work.
I also use the sourcecode with some modifications as you posted.