How to retrieve submission timestamp for use in get_value_XXX hooks?

Home Forums Quform WordPress How to retrieve submission timestamp for use in get_value_XXX hooks?

This topic is: resolved
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #26640
    katw
    Participant

    Hi 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

    #26701
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #26709
    katw
    Participant

    Yes 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

    #26724
    katw
    Participant

    Would 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;

    #26725
    katw
    Participant

    Hi 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.

    • This reply was modified 5 years, 7 months ago by katw.
    • This reply was modified 5 years, 7 months ago by katw. Reason: Fixed code indent
    #26728
    katw
    Participant

    OMG I need a drink to celebrate.

    After much detective work I found a formatDate() function that does a translation and gmt_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 formats Date() does.

    So anyone hooking in, using this new $customformat parameter would need to be aware of this.

    So for future release:

    1. expose date for use in hooks in all environments: ‘listview’, ‘editentry’, ‘viewentry’, ‘frontend’
    2. Add $customDateFormat parameter to formatDate() in options.php

    Many thanks, close ticket

    • This reply was modified 5 years, 7 months ago by katw. Reason: add summary
    #26767
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy