When uploading a file I get the following error:

    Warning: Invalid argument supplied for foreach() in file_field_widget_submit() (line 756 of /modules/file/file.field.inc).
    Warning: array_values() expects parameter 1 to be array, null given in file_field_widget_submit() (line 763 of  /modules/file/file.field.inc).

I came across this bug while building a similar file upload field for http://drupal.org/project/recline . I thought I was doing something wrong. I ended up getting rid of it by including the choices I was associating with the field field within the same array as the file: http://drupalcode.org/project/recline.git/blob/refs/heads/7.x-1.x:/recli...

When I saw the same error on OpenData I decided to do some more digging and found that this might be a regression that was introduced in Drupal 7.9: http://drupal.org/node/1329856

From looking at your code I think you did things correctly and imagine you did them before that regression was introduced. Anyway will post some more info as I come across it. Would be great to figure out how to correctly add additional elements to file uploads without that error message. Can you reproduce this?

Comments

webstudiodelta’s picture

I am having this issue as well, file attach field is being rendered into a form using field_attach_form() and upon upload it gives me the same two errors you are getting when I hit the upload button. The form will submit and the file will be added but the errors are unsightly and troubling. I also get this warning after submission:

Notice: Undefined index: career_app_form in career_inquiry_ticket_user_form_submit() (line 609 of /opt/dev/kazaamprojects/unitedchem/web/sites/all/modules/custom/career_inquiry/career_inquiry.module). =>

The real quandary is that I get no errors when I use the administration /add form that I created for the same entity and the forms are nearly identical.

EDIT: I have narrowed the case even further

in my form using this line to attach the file field works:
field_attach_form('career_inquiry_ticket', $entity, $form, $form_state);

however this line (which adds field grouping for ajax submission) results in the two errors the OP and I are both getting:
field_attach_form('career_inquiry_ticket', $entity, $form['career_app_form_wrap']['career_app_form'], $form_state);