Sometimes we need to display our node form in some other pages or simply in a block of front page.
Here is the code snippet which can render our node form in any block or any other page:
for a page:
module_load_include('inc', 'node', 'node.pages');
$form = node_add('nodetype');
$output = drupal_render($form);
if need to render in block:
module_load_include('inc', 'node', 'node.pages');
// Create a node for the content type.
$node = new stdClass();
$node->uid = $user->uid;
$node->name = $user->name;
$node->type = 'CONTENT_TYPE_NAME';
$node->language = LANGUAGE_NONE;
// Create the form.
$form = drupal_get_form('CONTENT_TYPE_NAME_node_form', $node);
$block = array(
'subject' => t(''),
'content' => drupal_render($form),
);
return $block;
There is a module available using which we can create these type of node form blocks:
https://www.drupal.org/project/nodesinblock
0 Comment(s)