file_field_widget_form has a line that looks like this (right before the return statement):
$elements['#file_upload_description'] = theme('file_upload_help', array('description' => '', 'upload_validators' => $elements[0]['#upload_validators']));
The issue is with the $elements[0] bit, a little earlier there is a small condition that looks like this:
if (($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta < $field['cardinality']) && empty($form_state['programmed'])) {
$elements[$delta] = $element;
$elements[$delta]['#default_value'] = $defaults;
$elements[$delta]['#weight'] = $delta;
$elements[$delta]['#required'] = ($element['#required'] && $delta == 0);
}
Obviously this block of code can't execute if $form_state['programmed'] is set (which it is when you submit a form problematically). Which in turn means that $elements[0] never exists and we get an undefined index warning.
The problem arises when calling drupal_form_submit on a node form with a file attachment field. I am basically calling it like this:
drupal_form_submit("{$node->type}_node_form", $form_state, $node);
The form state before I call drupal_form_submit looks like this:
Array
(
[values] => Array
(
[title] => some title
[name] => admin
[op] => Save
[field_person] => 88
[field_lead_type] => 1
[field_lead_details] => some stuff
)
)
And the node form I am submitting to has a file attachment field (but it is optional).
The node is created and everything, the only issue is a warning:
Notice: Undefined offset: 0 in file_field_widget_form()
Seems like the condition I posted above needs review in this case?