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)!!!

Files: 
CommentFileSizeAuthor
#23 undefined_index_file_ajax-1336212-23.patch505 bytesguillaumev
PASSED: [[SimpleTest]]: [MySQL] 39,581 pass(es).
[ View ]
#9 filetest.tar_.gz718 bytesarnoldbird

Comments

rfay’s picture

Category:bug» support

It 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.

magnusk’s picture

I'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:

function file_ajax_upload() {
  module_load_include('inc', 'node', 'node.pages');

The errors ended with the file_ajax_upload messages, but started with

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'node_form' not found or invalid function name in drupal_retrieve_form() (line 787 of /.../drupal-7.12/includes/form.inc).
magnusk’s picture

Category:support» bug
Priority:Normal» Major
magnusk’s picture

Version:7.9» 7.12
filijonka’s picture

Status:Active» Postponed (maintainer needs more info)

how do we reproduce this problem? Have you done this on a clean installation?

arnoldbird’s picture

I'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...

global $user;
module_load_include('inc', 'user', 'user.pages');
$form = drupal_render(drupal_get_form('user_profile_form', $user));

$output =  array(
      'himain' => array(
        '#type' => 'markup',
        '#markup' => $form,
      )
    );
return $output;

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...

    Notice: Undefined index: user_profile_form in drupal_retrieve_form() (line 752 of /var/www/hiusa/public_html/includes/form.inc).
    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'user_profile_form' not found or invalid function name in drupal_retrieve_form() (line 787 of /var/www/hiusa/public_html/includes/form.inc).
    Notice: Undefined index: #user_category in block_form_user_profile_form_alter() (line 563 of /var/www/hiusa/public_html/modules/block/block.module).
    Notice: Undefined index: #user_category in contact_form_user_profile_form_alter() (line 216 of /var/www/hiusa/public_html/modules/contact/contact.module).
    Notice: Undefined index: #user_category in logintoboggan_form_user_profile_form_alter() (line 160 of /var/www/hiusa/public_html/sites/all/modules/logintoboggan/logintoboggan.module).
    Notice: Undefined index: #user_category in overlay_form_user_profile_form_alter() (line 85 of /var/www/hiusa/public_html/modules/overlay/overlay.module).
    Notice: Undefined index: #user_category in system_form_user_profile_form_alter() (line 1954 of /var/www/hiusa/public_html/modules/system/system.module).
    Notice: Undefined index: field_image in file_ajax_upload() (line 270 of /var/www/hiusa/public_html/modules/file/file.module).
    Notice: Undefined index: #suffix in file_ajax_upload() (line 279 of /var/www/hiusa/public_html/modules/file/file.module).

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.

magnusk’s picture

Status:Postponed (maintainer needs more info)» Active

I had no problem until upgrading to 7.12.
I don't know what changed in core to seemingly cause the problem.

catch’s picture

Version:7.12» 8.x-dev
Status:Active» Postponed (maintainer needs more info)
Issue tags:+needs backport to D7

This 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.

arnoldbird’s picture

Version:8.x-dev» 7.12
Status:Postponed (maintainer needs more info)» Active
StatusFileSize
new718 bytes

I can reproduce the bug on a fresh install. How to reproduce the bug:

  1. Fresh install of drupal 7.12.
  2. Install the attached module, filetest. This module creates a very simple page with an embedded user_profile_form.
  3. Go to the modules admin page and enable the filetest module. Also, make sure the boxes are ticked for the image and file modules. (I don't remember if file and image are ticked by default.)
  4. Go to admin/config/people/accounts/fields -- create a new image field.
  5. Go to ?q=myadmin/1 and attempt to upload an image using the field you added in step #3. The upload itself will succeed, but you will see errors like the ones pasted below. To the user it will initially appear as though the upload failed, until you reload the page.

Notice: Undefined index: user_profile_form in drupal_retrieve_form() (line 752 of /var/www/drupal7fresh/includes/form.inc).
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'user_profile_form' not found or invalid function name in drupal_retrieve_form() (line 787 of /var/www/drupal7fresh/includes/form.inc).
Notice: Undefined index: #user_category in block_form_user_profile_form_alter() (line 563 of /var/www/drupal7fresh/modules/block/block.module).
Notice: Undefined index: #user_category in overlay_form_user_profile_form_alter() (line 85 of /var/www/drupal7fresh/modules/overlay/overlay.module).
Notice: Undefined index: #user_category in system_form_user_profile_form_alter() (line 1954 of /var/www/drupal7fresh/modules/system/system.module).
Notice: Undefined index: field_image in file_ajax_upload() (line 270 of /var/www/drupal7fresh/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 279 of /var/www/drupal7fresh/modules/file/file.module).

plach’s picture

Version:7.12» 8.x-dev

This 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).

arnoldbird’s picture

Much like #2, it appears this works in my situation...

function file_ajax_upload() {
  module_load_include('inc', 'user', 'user.pages');

More of a workaround than a solution, I suppose.

arnoldbird’s picture

Here'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.

emcniece’s picture

Getting the same thing for a node_add form - how can #12 be modified to fit these errors?

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'node_form' not found or invalid function name in drupal_retrieve_form() (line 795 of /var/www/html/includes/form.inc).
Notice: Undefined index: #node in comment_form_node_form_alter() (line 1193 of /var/www/html/modules/comment/comment.module).
Notice: Trying to get property of non-object in comment_form_node_form_alter() (line 1210 of /var/www/html/modules/comment/comment.module).
Notice: Undefined index: #node in menu_form_node_form_alter() (line 629 of /var/www/html/modules/menu/menu.module).
Notice: Trying to get property of non-object in menu_form_node_form_alter() (line 629 of /var/www/html/modules/menu/menu.module).
Notice: Undefined index: #node in menu_form_node_form_alter() (line 630 of /var/www/html/modules/menu/menu.module).
Notice: Trying to get property of non-object in menu_form_node_form_alter() (line 630 of /var/www/html/modules/menu/menu.module).
Notice: Undefined index: field_obs_image in file_ajax_upload() (line 271 of /var/www/html/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 280 of /var/www/html/modules/file/file.module).
vlad.dancer’s picture

When i tried to embed node_add form on other node view page i got the same error. Fixed in hook_menu_alter

<?php
 $items
['file/ajax']['file'] = 'node.pages.inc';
 
$items['file/ajax']['file path'] = drupal_get_path('module', 'node');
?>
emcniece’s picture

Nice, 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.

tim.plunkett’s picture

Priority:Major» Normal
Status:Active» Postponed (maintainer needs more info)
Issue tags:+Needs issue summary update

The attachment in #9 contains the following code:

module_load_include('inc', 'user', 'user.pages');
$form = drupal_render(drupal_get_form('user_profile_form', $account));

$output =  array(
  'himain' => array(
    '#type' => 'markup',
    '#markup' => $form,
  )
);

The correct way to do this is as follows:

$form_state['build_info']['args'][] = $account;
form_load_include($form_state, 'inc', 'user', 'user.pages');
$form = drupal_build_form('user_profile_form', $form_state);

$output = array(
  'himain' => $form,
);

Can someone clarify that they were able to reproduce this bug with only core, and no custom modules?

julescone’s picture

Interestingly 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.

sbandyopadhyay’s picture

tim.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...

<?php
form_load_include
($form_state, 'inc', 'node', 'node.pages');
?>

...OR...

<?php
form_load_include
($form_state, 'inc', 'user', 'user.pages');
?>

...depending on whether the core Drupal form you're loading is a node form or a user form.

nod_’s picture

Status:Postponed (maintainer needs more info)» Fixed

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

poorva’s picture

Hi 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:

<?php
module_load_include
('inc', 'node', 'node.pages');
$company = node_load(13);
print
drupal_render(drupal_get_form('article_node_form', $company));
?>

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

shumer’s picture

Version:8.x-dev» 7.19

I have the same issue and my problem has been resolved by help of #14.
Thanks.

guillaumev’s picture

Status:Closed (fixed)» Needs review
StatusFileSize
new505 bytes
PASSED: [[SimpleTest]]: [MySQL] 39,581 pass(es).
[ View ]

Here is a patch for version 7.x based on #14.

ezra-g’s picture

Status:Needs review» Needs work

I 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."

rerooting’s picture

Hmmm... 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

Majdi’s picture

I 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

<?php
function drupal_retrieve_form($form_id, &$form_state) {
     
form_load_include($form_state, 'inc', 'user', 'user.pages');
     
form_load_include($form_state, 'inc', 'node', 'node.pages');
?>

what is the solution to solve this ?

Majdi’s picture

Issue summary:View changes

fixed formatting

jesss’s picture

In 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.

swim’s picture

This 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.

<?php
$form_state
['build_info']['args'][] = $node;
form_load_include($form_state, 'inc', 'node', 'node.pages');
$form = drupal_build_form('node_form', $form_state);
?>
dcam’s picture

Version:7.19» 7.x-dev
Status:Needs work» Fixed
Issue tags:-needs backport to D7

I'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.

Status:Fixed» Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ckhung’s picture

For 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 .

sadanand kenganal’s picture

I changed the file permission but no success. But #14 is worked for me.

pratip.ghosh’s picture

#26 worked for me.