Sauter la navigation

[Résolu] $_POST does not return a strtotime format?

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: I would like to access the value of a datepicker field in a cred_save_data callback, but it doesn't seem to be usable Unix timestamp.

Solution: Datepicker fields contain an array of information. The 'datepicker' key contains the timestamp you can use.

$date = $_POST['wpcf-date-evenement']['datepicker'];
// $date is now a Unix timestamp
This support ticket is created Il y a 5 années et 7 mois. 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par Pat Il y a 5 années et 7 mois.

Assisté par: Christian Cox.

Auteur
Publications
#1249883

Pat

Hello,

I have a Cred that define a date thanks to a datepicker (custom field 'wpcf-date-evenement')
Now, I have a function (cred_save_data) inside a snippet that uses this info in order to update the post title.

So, I have this code inside the function :

$date = $_POST['wpcf-date-evenement'];
$datejour = date('d-m-Y', $date);

The result I'm getting for $datejour is : 01-01-1970 and the date used for that is may, 25th 2019

Can you tell me how I can retrieve the right date ?

Regards
Pat

#1250271

If you error_log print_r the field information from $_POST you can see that datepicker fields have an array of information and not just a value. Here is an example where the date field is empty:

[wpcf-book-date] => Array
        (
            [display-only] =>
            [datepicker] =>
        )

Here is another example where the date field is set to May 20 2019:

[wpcf-book-date] => Array
        (
            [display-only] => May 20, 2019
            [datepicker] => 1558310400
            [datetime] => 2019-05-20
            [hour] => 00
            [minute] => 00
            [timestamp] => 1558310400
        )

So you should update your code to use the datepicker key for best results:

$date = $_POST['wpcf-date-evenement']['datepicker'];

You may need a conditional in case the date is not set.

#1250611

Pat

Hi Christian,

Perfect ... as usual !

May I suggest an improvement : it would be good to add this kind of info in the Toolset documentation (in the developer ressources for example), as it is not easy to find this info otherwise (I have spent almost 2 hours trying to figure out what I should put here to get the right date !).
And even with your example, I'l not sure to have all potential parameters !

Another way to manage this would be to give a kind of code that could be used to get the info thanks to the error log ?

Regards
Pat