Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I try to upload an attached file (using a file field) I get the following error:
Notice: Undefined index: field_attachments in file_ajax_upload() (line 268 of /var/alternc/html/o/orangeseeds/usr/drupal-7/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 277 of /var/alternc/html/o/orangeseeds/usr/drupal-7/modules/file/file.module).
I have found other issues related to a similar bug but they are outdated or don't work.
Here are sample outputs from my log:
Location http://interdisciplinarities.orangeseeds.net/file/ajax/field_attachments/en/form-rN5xI6gbVameSuCglWOWiaLBcXZunFQrnmpqbEWvGTg
Referrer http://interdisciplinarities.orangeseeds.net/node/91/edit?render=overlay
Message Notice: Undefined index: #suffix in file_ajax_upload() (line 277 of /var/alternc/html/o/orangeseeds/usr/drupal-7/modules/file/file.module).
Location http://interdisciplinarities.orangeseeds.net/file/ajax/field_attachments/en/form-rN5xI6gbVameSuCglWOWiaLBcXZunFQrnmpqbEWvGTg
Referrer http://interdisciplinarities.orangeseeds.net/node/91/edit?render=overlay
Message Notice: Undefined index: field_attachments in file_ajax_upload() (line 268 of /var/alternc/html/o/orangeseeds/usr/drupal-7/modules/file/file.module).
What's even more strange: if I click "Save" right after it transforms my node into another type (Biblio)!!!
Comment | File | Size | Author |
---|---|---|---|
#23 | undefined_index_file_ajax-1336212-23.patch | 505 bytes | guillaumev |
#9 | filetest.tar_.gz | 718 bytes | arnoldbird |
Comments
Comment #1
rfayIt sounds to me like you have a field named "attachments" which has been damaged. Please find out what entity has a field named "attachments" (field_attachments) and what it does, and figure out what's wrong there.
field_attachments is not a core drupal field, as far as I can tell.
Comment #2
magnusk CreditAttribution: magnusk commentedI've had a similar problem, and after disabling contrib modules and trying to narrow things down, my fix for the issue has been to include a file from the node module:
The errors ended with the file_ajax_upload messages, but started with
Comment #3
magnusk CreditAttribution: magnusk commentedComment #4
magnusk CreditAttribution: magnusk commentedComment #5
filijonka CreditAttribution: filijonka commentedhow do we reproduce this problem? Have you done this on a clean installation?
Comment #6
arnoldbird CreditAttribution: arnoldbird commentedI'm having the same problem, also in 7.12. I am trying to embed the user_profile_form in a custom page. Everything works except the image upload field. Here's my code in my custom page function...
Like I said, all's well except the file upload field. If I click "upload", the image field's AJAX response prints these errors to the form...
The upload actually succeeds when I submit the user profile form, though. So the errors printed out don't seem to be necessary. If, after submitting the user profile form, I go back and click "Remove" in the image field, I see the exact same errors. Again, the "remove" succeeds if I submit the form despite the errors.
Comment #7
magnusk CreditAttribution: magnusk commentedI had no problem until upgrading to 7.12.
I don't know what changed in core to seemingly cause the problem.
Comment #8
catchThis was supposed to be fixed by #561226: Forms (elements) need to able to specify include files to be loaded for building a long time ago.
This issue really needs clear steps to reproduce, starting with a clean Drupal 7 install, see http://drupal.org/node/1468198.
Comment #9
arnoldbird CreditAttribution: arnoldbird commentedI can reproduce the bug on a fresh install. How to reproduce the bug:
Comment #10
plachThis still needs to be fixed in the 8.x branch first.
Possibily related: #1404480: Notice: Undefined index: in file_ajax_upload() (line 258 of modules/file/file.module).
Comment #11
arnoldbird CreditAttribution: arnoldbird commentedMuch like #2, it appears this works in my situation...
More of a workaround than a solution, I suppose.
Comment #12
arnoldbird CreditAttribution: arnoldbird commentedHere's a better (not a hack) solution from @jaypan
http://drupal.org/node/1526300#comment-5859594
I don't know if jaypan's solution would work for tatien's situation, but I was getting very similar error messages and it worked for me.
Comment #13
emcniece CreditAttribution: emcniece commentedGetting the same thing for a node_add form - how can #12 be modified to fit these errors?
Comment #14
vlad.dancerWhen i tried to embed node_add form on other node view page i got the same error. Fixed in hook_menu_alter
Comment #15
emcniece CreditAttribution: emcniece commentedNice, vlad.dancer - thanks for posting.
I ended up using the Form Block module instead - it accomplished the same embedded node_add task and didn't produce any errors.
Comment #16
tim.plunkettThe attachment in #9 contains the following code:
The correct way to do this is as follows:
Can someone clarify that they were able to reproduce this bug with only core, and no custom modules?
Comment #17
julescone CreditAttribution: julescone commentedInterestingly I had exactly the same errors in my node_add form as listed in #13, but in my case the form with the Image field that was generating this error was being displayed using the Form Block module!
emcniece, your comments here (and in your other forum topic on the same subject) pointed me in the right direction.
I had a basic page called /add-idea that was including the add idea form for the idea content type, and it was working fine apart from this issue with the image field. When I use the add form directly (via "node/add/idea") the image field works fine.
My solution was to go the other way, avoid using the Form as a Block and use the form directly. I renamed the old add-idea page, then added add-idea as a url alias to /node/add/idea and modified my CSS for the old add-idea page so it worked on the /node/add/idea page directly.
The Form Block functionality is very useful though, so it would be great if this issue can be cleared up at some stage.
Hopefully this is useful to someone else. Like all Drupal devs, I really appreciate the amount of discussion that goes on here.
Comment #18
sbandyopadhyay CreditAttribution: sbandyopadhyay commentedtim.plunkett is right (as is Jaypan here) that form_load_include() is the way to solve this.
EDIT: For people finding this in the future, I'll provide a bit more documentation:
You're probably getting this error because you're trying to produce a core Drupal form inside of custom callback. If so, in your custom callback OR in a hook_form_alter, call either...
...OR...
...depending on whether the core Drupal form you're loading is a node form or a user form.
Comment #19
nod_Comment #21
poorva CreditAttribution: poorva commentedHi Théodore,
I was also having the same problem.
Here is the full description:
My requirement was to show node edit form in a block. So I have written following code in a custom block:
Then I was having same problem during image upload and remove.
Now by help of #14, It seems my problem has been resolved.
Thanks,
Poorva
Comment #22
shumer CreditAttribution: shumer commentedI have the same issue and my problem has been resolved by help of #14.
Thanks.
Comment #23
guillaumev CreditAttribution: guillaumev commentedHere is a patch for version 7.x based on #14.
Comment #24
ezra-g CreditAttribution: ezra-g commentedI can confirm that #23 resolved errors with a file upload field on a node form that wasn't at the typical node/add callback. However, I believe this fix would fail for non-node entities, so marking as "needs work."
Comment #25
rerooting CreditAttribution: rerooting commentedHmmm... confirmed @ezra yeah this patch still gives me the same error with Inline Entity Reference with product entities and image fields in some browsers. Has anyone seen this show up with commerce kickstart? That could get hairy!
I looked into it a bit and it seems a bit over my head, however, I feel like the more robust approach would be to modify the file_ajax_upload page callback to bring in more entity agnostic support, correct? Is it against core principles to use the module_exists() function to detect entity module and then load it's page callbacks, or could/should we use the core entity access to accomplish this? Lastly, might possibly a patch to entity resolve the issue with entities?
I'll give it a whirl, but I'll make no promises :P
Comment #26
Majdi CreditAttribution: Majdi commentedI confirm the problem related to php
On PHP 5.3.13 no problem at all
On 5.4.3 You will have the problem
for sure you need to add your forms in the way you see in #18
===========================================
EDIT
My site online and i have to fix this problem fast , I add this 2 lines on the top of drupal_retrieve_form and everything works fine
I have embedded from for user and node in many pages, my code was woking on php 5.3 but not working on php 5.4
what is the solution to solve this ?
Comment #26.0
Majdi CreditAttribution: Majdi commentedfixed formatting
Comment #27
jesss CreditAttribution: jesss commentedIn my case, this error was caused by a typo in one of my hook_form_alter() calls. I was filtering by $form['#node']['#type'] and accidentally used = instead of == in my if statement.
Comment #28
swim CreditAttribution: swim commentedThis issue is becoming confusing due to the number of solutions, especially for new people. When embedding a system form via a menu callback or not; #16 is the most appropriate solution.
At a minimum, this is required.
Comment #29
dcam CreditAttribution: dcam commentedI've read through the comments and haven't seen any reports that this bug has been reproduce-able with core, only custom modules.
If you're having this issue with a custom module, check out #16 or #18 for a possible solution.
I'm setting this back to Fixed.
Comment #31
ckhung CreditAttribution: ckhung commentedFor those who landed here by googling the error message without knowing exactly what happened, please verify the file permission before proceeding to modify your code. In my case I fixed the error without code modification after changing the ownership of the directories in sites/default/files/private/webform from root:root to apache:apache .
Comment #32
sadanand kenganal CreditAttribution: sadanand kenganal commentedI changed the file permission but no success. But #14 is worked for me.
Comment #33
pratip.ghosh CreditAttribution: pratip.ghosh commented#26 worked for me.
Comment #34
eangulo CreditAttribution: eangulo commented#18 worked for me ^^!
Comment #35
alesr CreditAttribution: alesr commentedI have an entity (relation) with a field I want to populate in a custom form.
Same error:
But none of the confirmed solutions work for me.
Are the solutions specific for node and user entities?
What if the file field is on an other entity type?
Comment #36
ThirstySix CreditAttribution: ThirstySix as a volunteer commentedYes. none of the above solutions are not working for me also. I am using the Custom drupal form.
Notice: Undefined index: my_field_namein file_ajax_upload() (line 271 of /home/var/www/...../modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 280 of /var/www/...../modules/file/file.module).
Thanks in advance.
Comment #37
arne_hortell CreditAttribution: arne_hortell commentedI have been diving into this issue and i really have a question...
Is it really correct that line 269-272 should look like this
269 // Retrieve the element to be rendered.
270 foreach ($form_parents as $parent) {
271 $form = $form[$parent];
272 }
In line 271, the actual form, which ajax got (above) is actually destroyed if $parent is not found within the $form, and it can actually not be that as the actual field is only found within $form['#node'][$parent]. Therefore its simply not possible to get the remove button to work as it simply is no form to render later.
Therefore, to me it looks like a bug here,
Anyone that can enlight me on the issue?
Comment #38
arne_hortell CreditAttribution: arne_hortell commentedIt turned out, some other distant module wasnt doing stuff correctly so after fixing that issue
it seems to work properly again.
Sorry for wasting someones time on this issue.
For my situation, it turned out to be a hook_form_alter which wasnt specific to the right nodetype so therefore it created lots of disturbances.