1

I have these code that render form right:

<?php
// we have to access the content of the global-scope variable $user
global $user;
//Checking if the user is registered
if(($user->uid == 0) && (arg(0) != 'user')){
drupal_goto('user/register');
}else{
module_load_include('inc', 'node', 'node.pages');
$form = node_add('MY_CONTENT'); return drupal_render($form);}
?>

but when upload some images in form widget return some 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 806 of /Users/umbilu/Sites/bedmyboat/includes/form.inc).
Notice: Undefined index: #node in comment_form_node_form_alter() (line 1206 of /Users/umbilu/Sites/bedmyboat/modules/comment/comment.module).
Notice: Trying to get property of non-object in comment_form_node_form_alter() (line 1223 of /Users/umbilu/Sites/bedmyboat/modules/comment/comment.module).
Notice: Undefined index: #node in i18n_node_form_node_form_alter() (line 434 of /Users/umbilu/Sites/bedmyboat/sites/all/modules/i18n/i18n_node/i18n_node.module).
Notice: Undefined index: actions in i18n_node_form_node_form_alter() (line 448 of /Users/umbilu/Sites/bedmyboat/sites/all/modules/i18n/i18n_node/i18n_node.module).
Warning: array_search() expects parameter 2 to be array, null given in i18n_node_form_node_form_alter() (line 448 of /Users/umbilu/Sites/bedmyboat/sites/all/modules/i18n/i18n_node/i18n_node.module).
Notice: Undefined index: #node in maxlength_form_alter() (line 188 of /Users/umbilu/Sites/bedmyboat/sites/all/modules/maxlength/maxlength.module).
Notice: Trying to get property of non-object in maxlength_form_alter() (line 188 of /Users/umbilu/Sites/bedmyboat/sites/all/modules/maxlength/maxlength.module).
Notice: Undefined index: #node in menu_form_node_form_alter() (line 629 of /Users/umbilu/Sites/bedmyboat/modules/menu/menu.module).
Notice: Trying to get property of non-object in menu_form_node_form_alter() (line 629 of /Users/umbilu/Sites/bedmyboat/modules/menu/menu.module).
Notice: Undefined index: #node in menu_form_node_form_alter() (line 630 of /Users/umbilu/Sites/bedmyboat/modules/menu/menu.module).
Notice: Trying to get property of non-object in menu_form_node_form_alter() (line 630 of /Users/umbilu/Sites/bedmyboat/modules/menu/menu.module).
Notice: Undefined index: #node in translation_form_node_form_alter() (line 135 of /Users/umbilu/Sites/bedmyboat/modules/translation/translation.module).
Notice: Trying to get property of non-object in translation_form_node_form_alter() (line 135 of /Users/umbilu/Sites/bedmyboat/modules/translation/translation.module).
Notice: Undefined index: #node in i18n_menu_form_node_form_alter() (line 786 of /Users/umbilu/Sites/bedmyboat/sites/all/modules/i18n/i18n_menu/i18n_menu.module).
Notice: Trying to get property of non-object in i18n_menu_form_node_form_alter() (line 787 of /Users/umbilu/Sites/bedmyboat/sites/all/modules/i18n/i18n_menu/i18n_menu.module).
Notice: Trying to get property of non-object in i18n_menu_form_node_form_alter() (line 792 of /Users/umbilu/Sites/bedmyboat/sites/all/modules/i18n/i18n_menu/i18n_menu.module).
Notice: Undefined index: #node in _i18n_node_form_node_form_alter() (line 501 of /Users/umbilu/Sites/bedmyboat/sites/all/modules/i18n/i18n_node/i18n_node.module).
Notice: Trying to get property of non-object in _i18n_node_form_node_form_alter() (line 520 of /Users/umbilu/Sites/bedmyboat/sites/all/modules/i18n/i18n_node/i18n_node.module).
Notice: Undefined index: field_boat_images in file_ajax_upload() (line 271 of /Users/umbilu/Sites/bedmyboat/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 280 of /Users/umbilu/Sites/bedmyboat/modules/file/file.module).

I have tried with these:

<?php 
if (!function_exists('node_add')) {
module_load_include('inc', 'node', 'node.pages');
}
print drupal_render(node_add('on_board'));
?>

return these error:

Strict warning: Only variables should be passed by reference in eval() (line 5 of /Users/umbilu/Sites/bedmyboat/modules/php/php.module(80) : eval()'d code).

1

This problem is probably due to the fact, that node_add is registered as a menu callback in the node module, and in this menu item definition the include node.pages.inc is defined. When you use your own code (like you do) then this automatic inclusion of node.pages.inc is not done, so that the necessary API functions are missing, resulting in the error messages that you see.

Therefor, as a general remark, it is usually advisable to create custom modules (or adding functions to template.php, though no buisness logic should be processed there) and implement hooks like hook_preprocess_page or even define custom blocks in order to place functional elements in a page.

Anyway, for a solution to your problem, have a look at this question: Embed a "node add" form in a page

| improve this answer | |
  • Thanks for your answer. I have read How can I embed a "node add" form in a page, but it is little complex for me. Can you explain in very convenient way how to use that code? – Lutty Feb 10 '14 at 13:45
  • You should try to replace your original code with the first code snippet from the answer of Елин Й. Then you should create a custom module and add the function function YOURMODULE_menu_alter(&$items) where YOURMODULE must be replaced with the name of your module. Ideally you would also put the first code snippet in this same module file inside a hook_preprocess_page(). See Understanding the hook system for Drupal modules for more details about how to use hooks. – berliner Feb 10 '14 at 14:23
0

Try using Form Block module which provides user registration and node creation forms in blocks.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.