Skip Navigation

[Closed] Gravity Forms pass date value to Date format custom fields – UNIX format

This support ticket is created 10 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 12 replies, has 4 voices.

Last updated by Caridad 10 years, 1 month ago.

Assigned support staff: Caridad.

Author
Posts
#34809

Hi there,

I wish to inquire if there's a way for us to re-format a field if a data enter is invalid or in a different format.

A data being passed to the custom field using Gravity Forms and Gravity Forms + CPT plugin. Whenever a user submit a form, all data being submitted correctly except the date format. After looking at the postmeta, it seems that the data is in a UNIX format. How do I make sure that correct data is displayed?

Initially, I have submitted a support ticket to the plugin developer and they suggested me to contact Gravity Forms, and I realized that maybe Types could do something about it.
wordpress.org/support/topic/date-format-value-did-not-passed-to-the-custom-field-created?replies=1

Screencast: hidden link

#34858

Dear Antony,

Does the date format in WordPress -> Settings -> General match the date settings in the form field? d/m/Y

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#34991

Yes, I actually make sure it is match. Both for both dmY and mdY. I realized that the data is stored in UNIX format? Any particular reason for this?

#35111

Dear Antony,

The timestamp is only an internal format. You can format the timestamp for display with the date functions:
http://codex.wordpress.org/Function_Reference/date_i18n

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#35194

I have tried troubleshooting this issue with two plugin developers and it seems that the value passed by Gravity Forms is in the d/m/Y format, this has been confirmed by the Gravity Forms support team - kindly read the thread here: hidden link

If you looked at the first screencast, the <b>Start Date</b> custom fields created with Types is the one that causing the issue. Instead of accepting standard format, it change it to unix format.

I'm interested how the data being stored and not display.

hidden link

Instead of passing a correct date, the custom field use 1/1/1970 which is weird.

#35202

Dear Antony,

The solution that they suggest is a good one, using filters. But this should be part of the 'bridge' plugin:

http://wordpress.org/extend/plugins/gravity-forms-custom-post-types/

By looking at the source code, this sort of code should work, but I havent been able to test it. Add it to your functions.php, but replace wpcf-date-field with whatever you find in the $post_data array:

add_filter("gform_post_data", 'set_my_date'), 10, 2);
function set_my_date($post_data, $form ) {
 //check if the form saves a post
 if ( $this->is_form_a_post_form($form) ) {
   // Here you can inspect $post_data to see the name and format of the value
   // var_dump($post_data)
   // if its coming as mdY and you want a timestamp, do this
   $post_data['wpcf-date-field'] = str_to_time($post_data['wpcf-date-field']);
 }
 return $post_data;
}

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#36189

The above didn't work for me. It just killed the site until I took it out of my functions file.

#36404

Hi there,

I have added the code as requested and fix the code error on the first line:

<b>add_filter('gform_post_data', 'set_my_date', 10, 2);</b>

However, after testing it. It seems like having an error soon after I submit the form:

URL: hidden link
Password to access the site: xxxxxxxxxxx

#36614

Dear Antony,

I’ll send you a private email right now asking you for some private information that will help me debug this issue for you. Please check your email in a couple of minutes, and if you don’t get it, let me know so I can send it again. Thanks.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#37047

Dear Antony,

I dont have permission to change the file and test this, but there are two errors in the code above.
You caught one, the other one is to change str_to_time to strtotime.
Can you try replacing it?

add_filter("gform_post_data", 'set_my_date', 10, 2);
function set_my_date($post_data, $form ) {
//check if the form saves a post
if ( $this->is_form_a_post_form($form) ) {
// Here you can inspect $post_data to see the name and format of the value
// var_dump($post_data)
// if its coming as mdY and you want a timestamp, do this
$post_data['wpcf-date-field'] = strtotime($post_data['wpcf-date-field']);
}
return $post_data;
}

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#38236

Hi, I have the same issue. I pasted the above code into the functions.php but when i submit my form i get an error.. Any more thoughts?

#56008

Dear Andrew,

Can you open a new thread and paste the error message? You can also post a reference to this thread.

Thanks,
Caridad

#56339

Dear Antony,

I replied to your email, please check.

Regards,
Caridad

The topic ‘[Closed] Gravity Forms pass date value to Date format custom fields – UNIX format’ is closed to new replies.