Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Field : field_date_1
Type : Date
Widget : Pop-up calendar
The settings for date field is as shown in 2 images

enter image description here
enter image description here

I get the values of a form_state into the $source_node and move that to $fs variable.The $source_node has date field stored as follows :

 [field_pt_date_1] => Array
        (
            [und] => Array
        (
                    [0] => Array
                        (
                            [value] => 2010-08-27 00:00:00
                            [timezone] => America/Phoenix
                            [timezone_db] => America/Phoenix
                [date_type] => datetime
                        )
             )

)

 $fs['values']['field_date_1']['und'][0]['value'] = date('m/d/Y', strtotime($source_node->field_date_1['und'][0]['value']));
  $fs['values']['field_date_1']['und'][0]['timezone'] = $source_node->field_date_1['und'][0]['timezone'];
  $fs['values']['field_date_1']['und'][0]['timezone_db'] = $source_node->field_date_1['und'][0]['timezone_db'];
  $fs['values']['field_date_1']['und'][0]['date_type'] = $source_node->field_date_1['und'][0]['date_type'];

......... The errors I am getting after executing the above code is as follows :

A valid date is required for date_1.

 drupal_form_submit('form_id', $fs, $source_node);
  $errors = form_get_errors();

And when checked the $errors variable I get

$errors = Array
(
 [field_date_1][und][0][value] => A valid date is required for <em class="placeholder">date_1</em>.
)
share|improve this question
 
date('m/d/Y', strtotime($source_node->field_date_1['und'][0]['value'])); why this conversion instead of the actual value ? –  jonhattan Oct 4 at 7:38
 
I had same code in D6 where it used the above date conversion and a comment was left that error will be produced while executing the drupal_execute() in D6 .So I made the changes.. Also I have tried by directly placing the value but it still gives me error. Pls help . I want that this issue be solved by the end of day. –  harshal Oct 4 at 7:43
 
When I use node_save() I dont get the same error. –  harshal Oct 4 at 10:09
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.