Hi,

I am using drupal_extectue to add nodes. When i try to add a date field i am getting validation error. i am using date popup and format 'YYYY-MM-DD'

I tried the following

$form_state['values']['field_termstartdate'][0]['value'] = "YYYY-MM-DDTHH:MM:SS";
$form_state['values']['field_termstartdate'][0]['value'] = "YYYY-MM-DD";

i got the error

"There are errors in Term Start Date:
* The dates are invalid.
"

$form_state['values']['field_termstartdate'][0]['value']['date'] = "YYYY-MM-DD";
$form_state['values']['field_termstartdate'][0]['value']['time'] = "HH:MM:SS";

i got the error

warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in /includes/database.mysqli.inc on line 323

Thank you
Deepak

Comments

Anonymous’s picture

I've tried both of the above methods and I'm getting the same errors. I'm also using Date Popup.

When I tried:

$form_state['values']['field_termstartdate'][0]['value'] = "YYYY-MM-DDTHH:MM:SS";
$form_state['values']['field_termstartdate'][0]['value'] = "YYYY-MM-DD";

I got the error:

"There are errors in Term Start Date:
* The dates are invalid."

When I tried

$form_state['values']['field_termstartdate'][0]['value']['date'] = "YYYY-MM-DD";
$form_state['values']['field_termstartdate'][0]['value']['time'] = "HH:MM:SS";

I got these errors:

warning: trim() expects parameter 1 to be string, array given in /sites/all/modules/date/date/date_token.inc on line 40.
warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in /includes/database.mysqli.inc on line 330.

When I tried assigning a timestamp:

$form_state['values']['field_termstartdate'][0]['value'] = $timestamp;

I got the error:

warning: Cannot use a scalar value as an array in /includes/form.inc on line 1341.

It seems like form.inc expects $form_state['values']['field_termstartdate'][0]['value'] to be an array, while date_token.inc and database.mysqli.inc expect it to be a string. Assigning a timestamp results in incorrect date values, so I'm using the second method (assigning ['date'] and ['time'] individually).

Thanks.

Update: None of these methods produce consistent, reliable results. I'm afraid I'm going to have to dump my date values into a CCK Textfield instead of a CCK Date field.

dariogcode’s picture

I'm not sure if this is the same, but I also experimenting this issue in D7, and same errors (Using in a res server request to another Drupal with D7).
I fixed this with a parameter all_day (Curiously this should be in same level than 'date', but module take this from the parent level


$value['field_tr_purchase_date']['und'][0] = array(
      'value' => array(
        'date' => date('m/d/Y - H:i:s', time())
      ),   
      'all_day' => false,
);

Note that 'und' is for D7, I think D6 may be similar

I hope this help you don't spend hours like me debugging.

notzach’s picture

I've been working on this with Drupal 6 most of the afternoon, apparently you have to format the date the same way that it is formatted in the widget on the node form. This worked for me:

$detail = array(
  'field_asu_event_detail_datetime' => array(
    array(
      'value' => array(
        'date' => date('m/d/Y', strtotime('2012-07-06 16:58:00')),
        'time' => date('h:iA', strtotime('2012-07-06 16:58:00')), 
      ),
    ),
  ),
)

You would do the same structure for your value2 key. I hope this helps someone figure this out.

karens’s picture

Status: Active » Fixed

That's the way drupal_execute works, you have to mimic exactly the form element. That's why it's hard to use drupal_execute and I recommend node_save() where you don't have to know how the form is constructed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.