Posted by webankit on August 10, 2012 at 8:04pm
When I am using this code
<?php
$format = 'Y-m-d H:i';
// Find value of date from database
$date_se = isset($sub_event[$i]['date']) ? $sub_event[$i]['date']: NULL;
$datetime = new DateTime($date_se, new DateTimeZone('UTC'));
$datetime->setTimeZone(new DateTimeZone('Asia/Kolkata'));
$form['mydate'] = array(
'#type' => 'date_popup',
'#title' => t('Select a date'),
'#date_format' => $format,
'#default_value' => $datetime->format($format),
'#timezone' => 'Asia/Kolkata',
'#date_label_position' => 'within', // See other available attributes and what they do in date_api_elements.inc
'#date_increment' => 15, // Optional, used by the date_select and date_popup elements to increment minutes and seconds.
'#date_year_range' => '-3:+3', // Optional, used to set the year range (back 3 years and forward 3 years is the default).
);
?>When I press Submit I get an error "The value input for field Select a date is invalid."
Comments
On second submit it accepts
On second submit it accepts my value.
But the other problem I am getting is to save date
<?php
module_load_include('inc', 'node', 'node.pages');
global $user;
$sub_event_node = (object) array(
'type' => 'sub_event',
'language' => LANGUAGE_NONE,
);
node_object_prepare($sub_event_node);
$sub_event_form_state = array();
$sub_event_form_state['values']['title'] = $form_state['value']['title'];
$sub_event_form_state['values']['name'] = $user->name;
$sub_event_form_state['values']['op'] = t('Save');
$sub_event_form_state['values']['field_date']['und'][0] = array(
'value' => array(
'date' => '2012-08-10',
'time' => '22:30:00',
),
'value2' => array(
'date' => '2012-08-10',
'time' => '22:30:00',
),
'timezone' => 'Asia/Kolkata',
'timezone_db' => 'UTC',
'date_type' =>datetime,
);
drupal_form_submit("sub_event_node_form", $sub_event_form_state, $sub_event_node);
?>
I get this error
The value 2012-08-10 22:30:00 does not match the expected format.