PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Form date and UTC

  1. michaelsilva
    Member

    I'm not the Michael in the picture, but share the name.

    Anyways, I've recently done stuff on the action hook gform_after_submission_$ID in order to get dates to play nicely with WP-Types. I basically did a strtotime() function call on some meta data for a date field. However, the form started showing the UTC date when hitting "edit" on the entry, and I am trying to format it back to the specified format JUST for the display purposes. The person I'm helping pointed me to this filter: gform_pre_render but I can never seem to get the actual value that will show in the form when editing. All I really need is to show the UTC date in human readable when it comes to hitting edit, and still save as UTC in the db. Any help would be appreciated.

    Posted 11 years ago on Monday July 2, 2012 | Permalink
  2. David Peralty

    Hi, the gform_pre_render hook is for front end. If you are trying to edit it in the entries panel, you will want to use the following hook with the same function you are using:

    http://www.gravityhelp.com/documentation/page/Gform_admin_pre_render

    Posted 11 years ago on Monday July 2, 2012 | Permalink
  3. michaelsilva
    Member

    What I have going is for both:

    [php]
    add_filter("gform_pre_render", "msmb_date_format");
    add_filter("gform_admin_pre_render", "msmb_date_format");
    function msmb_date_format($form){
    	if($form["id"] != 2) return $form;
    	/*$orig = $form['fields'][1]['postCustomFieldName'];*/
    	/*$form['fields'][1]['postCustomFieldName'] = date('F d, Y', $thedate);*/
    	return $form;
    }

    I'm mostly struggling with how to retrieve the actual value stored in the meta field "wpcf-date" which is what one of the form fields saves to. Once I can actually retrieve that, I can filter it through date() right before showing in the input field. Hopefully this is making sense.

    Posted 11 years ago on Monday July 2, 2012 | Permalink
  4. wpcf-date is the meta key for a date which is stored as the meta value? If that's the case, you probably need to use the WordPress function get_post_meta.

    http://codex.wordpress.org/Function_Reference/get_post_meta

    Is it more complicated than that, or did I miss something? Is the value stored as post meta or something else?

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  5. michaelsilva
    Member

    I believe it is a meta field, but I'm struggling to find the right ID to use in get_post_meta. I've wondered if it's stored in the $entries object by chance. If not, I may need to just tinker and try IDs associated with the form. Would doing a global $post help, in your opinion?

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  6. Looking back at this, where did "wpcf-date" come from? Normally, meta keys use an underscore, but maybe that's just a typo. I am just wondering where you got that key from though. Where you see that will influence how we get the value out.

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  7. michaelsilva
    Member

    I believe it's coming from WP-Types plugin, which would explain why it's not underscored like GF does. I think I'm going to try a global $post and see what that brings about. Will report back.

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  8. Can you show a screenshot of exactly WHERE you see that meta key? Use something like phpMyAdmin to view the database, or the SQL that the plugin uses or something?

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  9. michaelsilva
    Member

    May be a couple hours before i get the db information. Thanks for the help thus far Chris and David. While waiting for access, I'll try a few things.

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  10. michaelsilva
    Member

    Eh, did a db backup plugin, with ctrl+f. Looks like the wpcf-date is in the wp_postmeta table, which would logically say I just need to find a way to get the right ID value.

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  11. You just need the key (which you have) and the post ID. Are you creating a post with your Gravity Form? If so, you have access to the post ID using the gform_after_submission hook. If you need it for a post which is already created, then a global $post is probably the way to go, so you can pull it into your form which is being rendered on that post/page.

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  12. michaelsilva
    Member

    I've come to discover that the number at the end of this is the ID I need:

    ?gform_post_id=789

    I am at the point of trying to retrieve that value when in the function being attached to this hook.

    I'm close, I can feel it

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  13. michaelsilva
    Member

    ah, I'll just use $_GET['gform_post_id']. It seems to work well enough :D

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  14. michaelsilva
    Member

    After some closer inspection and questions, I have come to realize that this is all controlled by this plugin: http://wordpress.org/extend/plugins/gravity-forms-update-post/

    I started wondering if I had the right filter once I realized that with the gform_pre_render, there didn't really seem to be a way to update the wp_postmeta value for 'wpcf-date'.. So in a way I'm back at square one. I am presently trying to see if I can properly filter part of what goes into the plugin's public gform_pre_render() function. Inside it does an apply_filters() to gform_update_post_id and appears to pass in gform_post_id, but that doesn't seem to hold a value I want. Maybe this post will help clear up some confusion, and I wish I realized it was the plugin instead of core GF earlier than I did.

    Posted 11 years ago on Tuesday July 3, 2012 | Permalink
  15. I would recommend contacting the author of that plugin in this case.

    Posted 11 years ago on Wednesday July 4, 2012 | Permalink
  16. michaelsilva
    Member

    10-4

    Posted 11 years ago on Wednesday July 4, 2012 | Permalink
  17. Let us know how it turns out. Good work so far.

    Posted 11 years ago on Wednesday July 4, 2012 | Permalink