Hi,
I'm trying to dynamically populate a date field so that the user can see the existing entry and then update it using the date field (with date picker) as normal.
This process has not been a problem for every other field type I've tried and I'm sure it's not for the Date Field, however I can populate the field but the field isn't interpreting the data as I expected. I've used a date field to save the data (in this case the original date is 08/12/1965 and that's how it outputs around the site, but the database stores it as -128304000. Obviously this must be correct as everything else seems to understand it, so I expected when I passed it back to the Date Field as a string it would understand it and convert it, but it doesn't it just displays -128304000.
I can find no mention of this in the documentation or elsewhere in these forums, could someone help me interpret this please?
Here's my code, as you can see I've tried using the php date() function, but to no effect:
add_filter('gform_field_value_original_dob', 'original_dob'); //Dynamically populate the original dob field
//Populate the original date of birth edit field
function original_dob() {
$post_id = $_GET['original_post_id']; //Pass GET function to pull variable from query string
$post_field = "-date-of-birth"; //Supply the bit of the field name specific to this item
$data = populate_edit_field($post_id, $post_field); //Build full funtion to find the required item of data
$date = date('d/m/Y', $data);
return $date;
}
//Function to build the command to and find the field data
function populate_edit_field ($post_id, $post_field) {
$post_type = get_post_type($post_id); //Use get_post_type to find the type of post, this is used as the part of the field name that changes for each type, such as "wpcf-surgery-street-address"
$database_field = "wpcf-" . $post_type . $post_field; //Build complete field name
$post_data = find_post_data($post_id, $database_field, true); //Finally find the contents of the field and post it back to the form
return $post_data;
}
//Retrieve post meta based on the post id passed via query string to the form
function find_post_data($postid, $fieldname, $returntype) {
global $post; //Call the global $post variable to access stored data
$value = get_post_meta($postid, $fieldname, $returntype); //Return the contents of the requested field for the passed post id
return $value;
}
add_action("gform_after_submission_26", "update_dob", 10, 2); //Update the edited date of birth in the database
//Update the existing monitor dosage system type post on submitting the form
function update_dob($entry) {
update_post_meta($entry[1], "wpcf-patient-date-of-birth", $entry[2]); //Update the post (stored in field 1), field name and the new value (stored in field 3)
}