Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Display node form in a different page of in a block

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 125
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: