I am trying to create my first custom module that creates a simple node type wcNames. This node type has two fields, firstname & lastname.
I could get my module create the DB table for node type and add it in node_type table, but when I open node/add/wc-name fields firstname and lastname don't appear.
Below is my code. Please suggest.

// wc_name.install file 
/*
 * hook_schema Implementation: Creates the DB and it's fields
 */
function wc_name_schema(){
    $schema['wc_name_names'] = array(
    'fields' => array(
      'nmid'              => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
      'firstname'        => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
      'lastname'         => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
    ),
    'primary key'        => array('nmid'),
    'unique keys'        => array(),
    'indexes' => array(
      'nmid'       => array('nmid'),
    ),
  );
    return $schema;
}

//function wc_name_install(){ } // Use this function to set variables for the module. 

function wc_name_uninstall(){ 
    //unset variables if any set 
    
   // Delete all wc_name nodes
  db_delete('node')->condition('type', 'wc_name')->execute();

  // Delete all wc_name tables
  db_drop_table('wc_name_names');
}
// wc_name.module
/*
 * Implementation of _node_info(): define node
 */
function wc_name_node_info(){
    return array(
    'wc_name' => array(
      'name' => t('wcName'),
      'base' => 'wc_name',
      'base' => 'page',
      'description' => t("A smaple module to save names."),
      'has_title' => TRUE,
      'title_label' => t('Title'),
      'has_body' => FALSE,
    )
  );

}

function wc_name_menu() {
  $items = array();
  $items['wc_name'] = array(
    'title' => 'wcNames',
    'page callback' => 'wc_name',
//   'access arguments' => array('access wcNames'),
  );
}

// wc_name_form.inc 
function wc_name_form($node, &$form_state){
       
    // Add fields
    $form['first_name'] = array(
    '#type' => 'textfield',
    '#title' => t('First name'),
    '#required' => FALSE,
    '#default_value' => $node->wc_name['firstname'],
  );
    
    $form['last_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Last name'),
    '#required' => FALSE,
    '#default_value' => $node->wc_name['lastname'],
  );
    return $form;
}

What am I missing?

Comments

pnick107’s picture

Waiting for a reply...

pnick107’s picture

Anyone?

pnick107’s picture

Moving wc_name_form() to .module file solved the problem.
Keeping it in wc_name_form.inc should have the same effect when it's being included in .module file.
Anyways...

pnick107’s picture

There was a space in one of the folder names in my windows machine.
Wasted an entire day :(