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.

Date field and timestamp format

  1. Hi,
    Is there a way to convert the date field value to the timestamp format when submitting the form?

    Thanks for your help!

    Cedric

    Posted 12 years ago on Monday November 12, 2012 | Permalink
  2. David Peralty

    No, but you could have a hidden text field, and using some PHP, you could fill in that field after submit by converting the date into a timestamp. Let me know if you want to work towards figuring this out. I can point you at a hook that might help you (grab the data).

    Posted 12 years ago on Monday November 12, 2012 | Permalink
  3. Using a hidden text field is a great idea (why didn't I think of that?) !

    But I will need help for the hook in order to grab the data !

    I assume that I have to use hooks like gform_pre_submission or gform_pre_submission_filter ?

    Posted 12 years ago on Tuesday November 13, 2012 | Permalink
  4. Ok,

    I tried something but it doesn't work.

    add_filter("gform_pre_submission_1", "convert_to_timestamp");
    function convert_to_timestamp($form){
    	$_POST['input_2'] = strtotime( $_POST['input_2'] );
    }

    The value is not returned and nothing is written to the database. But when I try with the following code :

    add_filter("gform_pre_submission_1", "convert_to_timestamp");
    function convert_to_timestamp($form){
    	$_POST['input_2'] = '2012/11/15';
    }

    The value '2012/11/15' is written to the database. Weird.

    Posted 12 years ago on Tuesday November 13, 2012 | Permalink
  5. Weird or not. GF must bypass the value if it is not a date format like 2012/11/13, right?

    I will try to achieve my goals using a hidden field. And I will let you know.

    Posted 12 years ago on Tuesday November 13, 2012 | Permalink
  6. David Peralty

    You'll want to put the value into another field. You can't send the timestamp through the date field. You'll want to have a hidden text field to carry the timestamp into the database. You are close though.

    Posted 12 years ago on Tuesday November 13, 2012 | Permalink
  7. Damned, you're fast! I was editing my post when you replied.

    Thanks for your help. I will let you know as soon as I will be victorious! :)

    Posted 12 years ago on Tuesday November 13, 2012 | Permalink
  8. Yeehaa, it was easy as f*** using hidden fields! Thanks for your help David!

    Posted 12 years ago on Thursday November 15, 2012 | Permalink
  9. David Peralty

    No problem, glad you got it sorted. I love shoving data into hidden fields. :)

    Posted 12 years ago on Thursday November 15, 2012 | Permalink

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