Home › Forums › Quform WordPress › How to retrieve submission timestamp for use in get_value_XXX hooks?
- This topic has 6 replies, 2 voices, and was last updated 6 years, 8 months ago by
Ally.
- AuthorPosts
- August 12, 2018 at 12:52 pm #26640
katw
ParticipantHi Ally,
How do I get the Entry DATE and Time (ie the Entry timestamp)?
I want to access it for decision logic within a
quform_get_value_html_#
hook.Ideally I want the date value in UTC – Date_W3C format
'Y-m-d\TH:i:sP'
.Many thanks
Katw
August 16, 2018 at 3:47 pm #26701Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 16, 2018 at 11:24 pm #26709katw
ParticipantYes I tried to use
getEntryID()
and fell on my face 😉 Same with {date} token.Can your function be used for edit-entry too? You didn’t specifically mention that.
My use-case: I want to extract date parts and generate a job-id. So need it in all admin modes.
Many thanks
August 18, 2018 at 4:04 am #26724katw
ParticipantWould be great to be able to get and refer to the timestamp in ListView.
I would like to format other fields according to the ‘age’ of the submission and can’t get the entry date value to reference.
Use-case example:
Field Text 1_95, with title = Urgency
Add Hook quform_get_value_html_1_95
If listview:
Get entry date;
If Entry date > 7 days then set CSS class ‘Overdue’;
If Entry date = now then set CSS class ‘Normal’;
If Entry date < 7 days then set CSS class ‘Action’;if entryview:
If Entry date > 7 days then display icon-red;
If Entry date < 7 days then display icon-yellow;if editview:
do nothing;
August 18, 2018 at 7:52 am #26725katw
ParticipantHi Ally,
I have a problem with the date returned using the code supplied.
For example I submitted a form at 4:26PM on 18 Aug 2018. I see this timestamp in Entry View ‘additional information’ and it is correct.
But your code Returns a date value of
2018-08-18 06:26:36
.
What happened to the ‘1’ prefix on the 24 hour clock?I put an echo in to shout out the value when we say
var = $entry['created_at'];
. It is this value I am referring to… it is showing wrong at the start.// Get entry or record ID (wont work for list-view) if (isset($_GET['page'], $_GET['sp'], $_GET['eid']) && $_GET['page'] == 'quform.entries' && $_GET['sp'] == 'view') { $entryId = (int) $_GET['eid'];//Extracts from querystring } else { $entryId = $form->getEntryId(); } // Access DB and get submitted data (all) if ($entryId) { $repository = Quform::getService('repository');//DB call $entry = $repository->findEntry($entryId, $form);//Returned dataset if ($entry) { // $entry['created_at'] will be a datetime in the format Y-m-d H:i:s $Qtime = $entry['created_at']; echo '<script language="javascript">'; echo 'alert("Q DATE [' . $Qtime . ']");'; echo '</script>'; } }
I have removed any date format settings for PHP in the QuForm Global Settings. (not that it has been working). No impact on outcome.
Please help. I just need to get the date and be able to trust the value.
If I do any date formatting on a compromised input value I just get a compromised output value GIGO.
August 18, 2018 at 10:22 am #26728katw
ParticipantOMG I need a drink to celebrate.
After much detective work I found a
formatDate()
function that does a translation andgmt_offset
correction to raw dates. This was what was missing in the code you supplied.After a few dismal hours of trying to replicate the steps performed by this function I was about to give up when I worked out a way to
call
it up instead.I now have a correct timestamp. Yay!
I do however ask in a future plugin version you add a new parameter to the
public function formatDate()
to allow us to pass a $dateformatstring.And have the function return the date in the custom format specified otherwise the locale setting (as it is now).
At the moment the date returned does not include seconds, and I need a UTC format.
BTW
I saw a few recent comments suggesting the WordPress
date_i18n
function doesn’t support all the formatsDate()
does.So anyone hooking in, using this new
$customformat
parameter would need to be aware of this.So for future release:
- expose date for use in hooks in all environments: ‘listview’, ‘editentry’, ‘viewentry’, ‘frontend’
- Add $customDateFormat parameter to formatDate() in options.php
Many thanks, close ticket
- This reply was modified 6 years, 8 months ago by
katw. Reason: add summary
August 21, 2018 at 11:15 am #26767Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.