How to create node from anywhere using call to node form?

    You can create node by using your own function to call the node form inside it anywhere on drupal pages.
    <?php
    /**
    * Replace these values in your code
    * <type> => Content type type.
    * <modulename> => Name of module.
    */
    function <modulename>_<type>_node_form() {
      global
    $user;
     
    module_load_include('inc', 'node', 'node.pages');
     
    $node = array(
       
    'uid' => $user->uid,
       
    'name' => $user->name,
       
    'type' => '<type>',
      );
      return
    drupal_get_form('<type>_node_form', $node);
    }
    /**
    * Removing Extra fields if you want to remove those using form alter.
    * You can add other fields also
    */
    function <modulename>_form_alter($form_id, &$form) {
       if (
    '<type>_node_form' == $form_id) {
         if (
    $_GET['q'] != 'node/add/<type>') {
          
    $remove_fields = array(
            
    'menu',
            
    'body_filter',
            
    'attachments',
           );
           foreach (
    $remove_fields as $field) {
             if (isset(
    $form[$field])) {
               unset(
    $form[$field]);
             }
           }
         }
       }
    }
    ?>
    5
    Average: 5 (1 vote)