By tomas.teicher on
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
What errors do you get? I'm
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:
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.
Node form displays and works
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).
I succesfully embedded the
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.
And found it. As
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:
This is necessary to make sure that node.pages.inc is always included and not only when creating the form.
Great! This works for me
Great! This works for me too.
Thank you
Tomas