Custom Drupal Module development

Today i am going to give you an idea about the Drupal 1.6 Module development .

Basic Steps :

  1. File Structure , naming and path :
    Path to place your module files sitesallmodules
    we need to create three files (basic need of drupal module).   , modulename.install  , modulename.module

  2. : This file will have your module information like
    In top of the file :

    ; $Id$
    name = Your module name (Which will be shon in admin)
    description = Your module name .
    core = 6.x
    function modulename_help($path, $arg) {
      switch ($path) {
        case 'admin/help#modulename':
          $output =  t('Some help discription') ;
          return $output;

    As above the menu will display the help content.

  3. modulename.install :This s the file that will run at the time when you install the module eachtime.Here you need to write two core important functions one for install and one for uninstall.
    for install you can see first Query that will give place our module in system DB ,so it will
    come into the module list in admin.

    // $Id: modulename.install
    * Implementation of hook_install()
    function modulename_install() {
      // Set the module weight so it can override other modules.
      db_query("UPDATE {system} SET weight = 99 WHERE name = 'modulename'");
    		db_query("CREATE TABLE IF NOT EXISTS `sometableforyourmodule` (
      `id` int(11) NOT NULL auto_increment,
      `catid` int(11) NOT NULL,
      `name` varchar(250) NOT NULL,
      `link` varchar(250) NOT NULL,
      `disc` text NOT NULL,
      PRIMARY KEY  (`id`)
    * Implementation of hook_uninstall()
    function addportfolio_uninstall() {
      // Remove variables which is defined in our module
  4. modulename.module : This is the main file for your functionality .
    you need to create menu function by which ur module will called .

    function addportfolio_menu() {
     $items = array();
        $items['admin/somename'] = array(
          'title' => 'title of page',
          'page callback' => 'drupal_get_form',
              'page arguments' => array('modulename_page_form'),
          'access arguments' => array('access content'),
          'type' => MENU_CALLBACK
      return $items;

    Here we are mentioning that the page will be the form
    drupal_get_form is the callback for a drupal form.
    and in page argument we are passing the function which will create the form in web page.

    function modulename_page_form() {
      $form['#attributes'] = array('enctype' => 'multipart/form-data');
        $form['Name'] = array(
        '#type' => 'textfield',
        '#title' => t('Enter Name of project'),
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
      return $form;

    $form array will create complete form.
    #attribute will set the form attribute .
    name is textfield.
    submit is a submit button .

    Now the important thing Where we need to write code after submit the form .

    function modulename_page_form_submit($form_id, $form_values) {
    //here is the section where you will get all the submited data
    // db_query('DB Query ') is the function which will run your database query

Hope this post will help you to create basic custom module in drupal 1.6 CMS.
if you have any Question feel free to ask .


Show Buttons
Hide Buttons