Creating node form with drupal_get_form works for me untill I have custom field for uploading images. After I click on Upload, instead of loading images with ajax it throws me many many errors. (I use Drupal 7)

<?php
 module_load_include('inc', 'node', 'node.pages'); 
    global $user;
  // create a blank node
  $node->uid = $user->uid;
  $node->name = (isset($user->name) ? $user->name : '');
  $node->type = 'ponuka';
  $node->language = '';

  // Invoke hook_nodapi and hook_node
  //node_object_prepare($node);

    $output= drupal_get_form('ponuka_node_form', $node);
?>

Have anybody similar experience?

Comments

lolbroek’s picture

What errors do you get?
I'm having a similar experience with embedding a node edit form for a custom node. This is the code:

$node = node_load($id);
drupal_get_form('mytype_form', $node);

And I get a warning and an error:
Warning: Illegal offset type in isset or empty in node_type_get_type() (line 404 of /var/www/modules/node/node.module).
Notice: Trying to get property of non-object in node_content_form() (line 3558 of /var/www/modules/node/node.module).

But the backtrace indicates that hook_form($node,$form_state) gets an empty array as first argument instead of $node. I don't know if it is related to your question (so then there might be an error in form.inc: when I make sure that the object is passed as first argument of the array in call_user_func_array at line 774 in form.inc, I get a form with only the title field...). If it is not related please tell me so i can open another thread.

tomas.teicher’s picture

Node form displays and works OK for me. I get errors only when using ajax upload of image field.
I don't know where your problem can be. Do you call module_load_include function before calling drupal_get_form?

I get these errors:

Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'node_form' was given v drupal_retrieve_form() (line 773 z /website/includes/form.inc).
Notice: Undefined index: #node v menu_form_node_form_alter() (line 605 z /website/modules/menu/menu.module).
Notice: Trying to get property of non-object v menu_form_node_form_alter() (line 605 z /website/modules/menu/menu.module).
Notice: Undefined index: #node v menu_form_node_form_alter() (line 611 z /website/modules/menu/menu.module).
Notice: Trying to get property of non-object v menu_form_node_form_alter() (line 611 z /website/modules/menu/menu.module).
Notice: Undefined index: field_hlavny v file_ajax_upload() (line 265 z /website/modules/file/file.module).
Notice: Undefined index: #suffix v file_ajax_upload() (line 274 z /website/modules/file/file.module).

lolbroek’s picture

I succesfully embedded the form, which has also an image field, and when I try to update that field in the embedded form (delete an image, upload an image,...) I get the same errors as you do. I'm going to look into that now.

lolbroek’s picture

And found it. As http://drupal.stackexchange.com/questions/3755/reusing-an-existing-form states, the hook_menu item that describes the page has to have the following associations in the array:

        'file path' => drupal_get_path('module','node'),
        'file' => 'node.pages.inc',

This is necessary to make sure that node.pages.inc is always included and not only when creating the form.

tomas.teicher’s picture

Great! This works for me too.
Thank you
Tomas