Forum
Need timestamp field for records in event app
Is there any way to get a field to record the time the record is saved in the event app?
Like a timestamp on the record that would update every time the record is submitted.
Ideally it would be a hidden field in the admin.
UPDATE: oops, I think that's the time/date of the event, not when it was updated.... Sorry
It's already there... as eventDateTime... Have you done a
<perch:showall />
in the template? It's also available on $Event->eventDateTime() on the Event object.So, now I ask you "When, where, how??" do you want to use this and I will try to help you further.
RK
You could add this as an additional field... and if push comes to shove create a new fieldtype to handle this... :)
I'm thinking it would be a timestamp field type. Is there one out there?
Datetime
Hi Robert, not sure I follow...
https://docs.grabaperch.com/templates/form/input/datetime/
This is what I was thinking, but now I see it’s just for perch forms
You could make a timestamp fieldtype pretty easily.
I think I would need help with that unfortunately...
How about adding a column of the type TIMESTAMP to the perch_events2 table called timestamp that has 'on update CURRENT_TIMESTAMP' set?
I've done that on my local server and I'm able to retrieve it in perch. It's working well there.
Would there be any adverse repercussions in doing it that way?
Here's my attempt at a timestamp field type. Is there a way to make the field un-editable in the admin? Or perhaps hidden altogether? I would appreciate any comments as to how to improve this.
Yes, you'd write your own
render_inputs
method - that's the part that gets called to display the form field.So I can hide the field value by adding:
But what would I do if I wanted to just add the tag
disabled="disabled"
to the input?I think the slug field type is a good example of this.
Thank you for that pointer! Here's my final timestamp field type. it does not allow for editing but updates the timestamp each time the record is saved. Any comments on the code would be appreciated.