Set date only on insert
Set date only on insert
alf007
Posts: 37Questions: 15Answers: 0
How can I set the date only on insert?
Here is part of my code:
Field::inst( 'modelos.create_date' )
->getFormatter( function ( $val, $data, $opts ) {
return date( 'd-m-Y', strtotime( $val ) );
} )
->setValue( date("Y-m-d") ),
The problem is that, when ever I update the row I update also the date. As you see I get the date when I add the record but I will like to set the date only when I add not when I update.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This is a perfect use case for server-side events. Listen for the
preEdit
event and set the value there.Allan
Thanks Allan.