I get image field upload errors with a custom node_add() form I've exposed a node_add form and styled it for certain roles to use. The form is being displayed in panels, through an 'article' node type using the PHP text filter. Users can create new nodes with no issues, but there are errors displayed when users try to upload an image in the form:


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


The actual node form code looks like this:

module_load_include('inc', 'node', 'node.pages');
$form = node_add('observation');
print drupal_render($form);


I have also tried this code with the same results:

$node_type = 'observation';
$form_id = $node_type . '_node_form';
// maybe add current users info
global $user;
// create a blank node

$node = new stdClass(); 
$node-&gt;uid = $user-&gt;uid; 
$node-&gt;name = (isset($user-&gt;name) ? $user-&gt;name : ''); 
$node-&gt;type = $node_type; 
$node-&gt;language = ''; 
node_object_prepare($node); 
$output = drupal_render(drupal_get_form($form_id, $node));

print $output;


The content type being added is 'observation'. I am also using the identical technique on another page with a different content type, and it results in the exact same error. The error appears directly above the image field during the AJAX image upload call.

I have also done a debug_backtrace() near line 795 of form.inc and can post the results if requested.

I have read all of these articles, to no avail:


"Notice: Undefined index: field_xxx in file_ajax_upload()" and "Undefined index: #suffix in file_ajax_upload"
D7 Image field upload errors with custom node_add() form
How to disable AJAX for a file field
The Field module shows an error when I call drupal_get_form()
Can&#39;t use file field in custom form - gives AJAX errors


Does anyone have an idea as to where I can start looking? This seems to be a tough problem. Thanks for your time!
I believe the problem is, roughly, that while you've ensured the include happens before initial form build, that include doesn't happen when the AJAX file upload processing attempts to rebuild the form... So node_form() function is undefined and things fall apart.

The solution that worked for me was to use form_load_include() in place of module_load_include(). According to its documentation, this alternate function exists for this express purpose - "ensures that the include file is loaded whenever the form is processed."