While trying to creating a node programmatically using 'drupal_form_submit' i've come across a php error in the form.inc code
Here's my code
function vl_sample_data_generate_yvbct1() {
module_load_include('inc', 'node', 'node.pages');
global $user;
$content = 'Generating YVB CT1';
$form_state = array();
$data = array();
$node = (object) array(
'uid' => $user->uid,
'name' => $user->name,
'type' => 'yvb_ct1',
'language' => LANGUAGE_NONE,
);
node_object_prepare($node);
$data['uid'] = $user->uid;
$data['created'] = time();
$data['type'] = 'yvb_ct1';
$data['language'] = LANGUAGE_NONE;
$data['title'] = 'Node created on ' . time();
$data['status'] = 1;
$data['op'] = 'Save';
$data['field_middle_name'][LANGUAGE_NONE][0]['value'] = 'Alex';
$data['field_gender'][LANGUAGE_NONE][0]['tid'] = 24;
$form_state['values'] = $data;
drupal_form_submit('yvb_ct1_node_form', $form_state, $node);
return $content;
}
The error i get when i run the function (as a menu callback) is
Warning: Illegal offset type in isset or empty in _form_validate() (line 1333 of /opt/httpd/htdocs/www/staging/jns/trunk/includes/form.inc). An illegal choice has been detected. Please contact the site administrator. Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 173 of /opt/httpd/htdocs/www/staging/jns/trunk/includes/entity.inc). Warning: Illegal offset type in taxonomy_field_validate() (line 1519 of /opt/httpd/htdocs/www/staging/jns/trunk/modules/taxonomy/taxonomy.module). Notice: Trying to get property of non-object in taxonomy_field_validate() (line 1519 of /opt/httpd/htdocs/www/staging/jns/trunk/modules/taxonomy/taxonomy.module).
However, if i comment out the line
$data['field_gender'][LANGUAGE_NONE][0]['tid'] = 24;
It works fine. Am using Drupal 7.26. Also, the term tid does exist and belongs to the valid Vocabulary which is assigned in the content type.
Any help regarding the above problem is appreciated.
Thanks
Yashesh