1

I'm building my own form for editing certain fields on a node type, and I'm using field_attach_form() to add the fields from that node type to my form.

Use field_attach_form() to get the fields added to the $form array, and then I hide the ones I don't need by setting them to '#access' => FALSE. For all the textual fields, selects, etc., there's no problem. But when I use a file field (for image uploads), and someone selects a file and clicks 'Upload' on that file field, I get the following two errors:

Notice: Undefined index: field_picture in file_ajax_upload() (line 268 of /path/to/drupal/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 277 of /path/to/drupal/modules/file/file.module).

I noticed over on drupal.org, merlinofchaos mentioned that a user could use form_load_include() to include an include that needs to be loaded with the particular form (see: http://drupal.org/node/1161430#comment-4540578), but that was more because that guy additionally had something else he was loading, I think.

The form is built in mymodule.pages.inc, and is called through a menu callback at a path like /admin/config/mymodule/edit-form. What am I missing?

2

This is a bug in Drupal. The patch in comment #6 works.

2

As it turns out, in my case, there was one place where I wasn't returning the proper form API array in the first step of the form processing, so when the file field tried refreshing/rebuilding the form via AJAX, it messed up the form state. A friend and I had to step through the entire submission process to figure out where we were losing the correct form state.

That was what happened to me; other people may be helped by the patch mentioned in V-A's answer, so I gave that an upvote as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.