I have a simple routine which I use to create nodes. The logic is something like this:
function make_node($node_type, $field_data) {
foreach ($field_data as $k => $detail) {
$field_key = _get_field_keys('field_' . $k);
$field_key = $field_key[0];
$node -> {'field_' . $k}[$node -> language][0][$field_key] = $detail;
$form_state['values']['field_' . $k] = $detail;
}
}
Then I run drupal_form_submit and it returns any errors from that and everything is great.
I’m having an issue with creating nodes which have a file upload field which uses the file u widget. I get the error:
Notice: Undefined offset: 0 in file_field_widget_form()
I had a look at the offending line (line 511 of modules/file/file.field.inc) and I can see why it occurs, the function file_field_widget_form has an argument called $element, which is supposed to have an index 0, but when I set up the form programatically, that index is not set up.
When I make a node of the same type using the web interface, I can see that the $elements array is set up with the 0 index before even submitting the form.
How do I rectify this issue, do I need to call something else before making my form programatically? I’m using Drupal 7 if it helps.