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.

Automatically Populate Time

  1. Is there a way to populate a "time" field with what time it currently is?

    Posted 8 years ago on Tuesday August 16, 2011 | Permalink
  2. The entry date and time are already captured and visible with the entry. Are you looking for more than that?

    a) When the page with the form loads, do you want the current time loaded there?

    b) Should it be visible to visitors or admin only?

    c) Should it be editable?

    d) Should it be the time the form is submitted rather than the time the page was loaded?

    It's certainly possible but how you want to use it determines how to go about getting the time.

    Posted 8 years ago on Wednesday August 17, 2011 | Permalink
  3. We're using it for a call logging system for a client, so they have a place where they would enter what time the call started (which would be the automatic time) and then when the call ended (which would be manually entered, I suppose).

    Does that help answer the question?

    I honestly hadn't thought about the form being logged automatically with a time stamp. :) That could be the "call conclusion" time for sure.

    Thanks!

    Posted 8 years ago on Wednesday August 17, 2011 | Permalink
  4. So, it sounds like you want the time populated when the page is loaded. It should probably be visible so the person loading the form can see that it's accurate (i.e. they are using a page that was loaded at a prior time inadvertently.)

    If you can accept the time the form was submitted as the call conclusion, I think it will be pretty easy. Just confirm if that's what you want to do and I will come up with a suggestion.

    Posted 8 years ago on Wednesday August 17, 2011 | Permalink
  5. Yes, exactly! :D

    Posted 8 years ago on Wednesday August 17, 2011 | Permalink
  6. OK. You're probably going to want to use the gform_field_value_ filter to pre-populate a field in your form.

    http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name

    Add a single line text field to your form, maybe call the field "Start Time" and check the box to "Allow field to be populated dynamically". That's on the advanced tab for your field. Once that's checked, you will be shown a text box called "Parameter name". In there, enter the name of the parameter you're going to be populating with your filter. Something simple like "start" would be fine.

    Then, in your functions.php (in your current theme) use the filter to populate the parameter "start" with the value of the current time. That will place the current time in your form before it's displayed.

    Your filter will look something like this in functions.php:

    [php]
    add_filter("gform_field_value_start", "populate_start_time");
    function populate_start_time($value){
       return date(DATE_RFC822);
    }

    Note the addition of "start" in the name of the filter: gform_field_value_start. That needs to match what you used as the parameter name when you said "Allow this field to be populated dynamically".

    You can use the PHP date function to craft a date/time format that will work for you. There is also a Gravity Forms function called format_date in common.php that you can use to help get the date displayed exactly the same way as the date the entry was created (for comparison.) I think you could probably also extend this to include some math to calculate the number of minutes, if that's required for your application.

    If you need additional help, please let us know.

    Posted 8 years ago on Wednesday August 17, 2011 | Permalink
  7. Worked perfectly!
    Thanks for the help, and the great instructions!

    Posted 8 years ago on Wednesday August 17, 2011 | Permalink
  8. Glad it worked out for you.

    Posted 8 years ago on Wednesday August 17, 2011 | Permalink

This topic has been resolved and has been closed to new replies.