Submit Hanlder In Custom Drupal Forms

How to invoke two different functions from hook_form() in Drupal?
This can be achieved using submit handler.

Here is the explanation with code.
1:-Use following code in your hook_form() function:-

$form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',

        //here we are defining the first submit handler and
          calling one submit function
        '#submit' => array('test_form_submit'),
        );  


$form['enter'] = array(
        '#type' => 'submit',
        '#value' => t('Enter'),

        //here we are defining the second submit handler and
          calling second submit function
        '#submit' => array('enter_submit'),
        );

    
2:- By using  #submit =>  array('function_name'),you can call N number of functions from custom one form.
 

Different Page Template for Different Content Type in Drupal

This is one of the most frequently asked question in the interviews that
how can you provide different style(in terms of HTML & CSS) to any particulate page or any particulate content type in drupal?

 Here is the step by step answer for this question.
1:-First go to your themes folder(whichever theme is currently active) and search for this function in template.php file.
phptemplate_preprocess_page(&$vars)

2:-Now Copy the following code inside this phptemplate_preprocess_page(&$vars)
function:-
   if (isset($vars['node'])) {
        // This code looks for any page-custom_content_type.tpl.php page
        $vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type); 
  }  

In the above code,I am checking the value for node,if its value is set(means if we are opening any node in our drupal site),than this if condition will be true and the code inside will get execute.

We are using $vars['template_files'] array for loading the template file from themes folder.

3:-Next step is to create new content type(or you can use existing content type).
    For example I am creating product content type.

4:-Now create one content of product content type.

5:-Create one file named page-product.tpl.php inside themes folder.Here product is our custom content type.

6:-Once we click on any content of product content type,the above will search for the template file with page-product.tpl.php name.If file is present inside themes folder,then it will take this template file other wise it will style take from page.tpl.php.    

7:-In this page-product.tpl.php file,we can provide the different style(HTML & CSS).

These Steps are useful for particular content type.You can provide different template to particular  page also by adding this code:- 
$vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->path);
Here we have replaced $vars['node']->type with $vars['node']->path(for specific path).

And create the template file with the name of your page url. For examples if you want different template for
test_image url.So create file page-test_image.tpl.php


Create Table Structure with Pagination in Drupal Using theme table


For creating tables in drupal, you don’t need to write html table tag structure.
It is very easy to implement this in drupal.

Here I am giving the step by step explanation with code:-

1:-First create a menu in hook_menu() function.
In this menu we will display the table using theme table.
function hook_menu() {
    $items = array();
    $items['theme_table'] = array(
            'title' => t('Theme Table'),
            //calling custom test_theme_table() function on this menu
            'page callback' => 'test_theme_table',
            'access arguments' => array('access content'),
            'type' => MENU_CALLBACK,
            );    
    return $items;
    }
2:- Code for test_theme_table function:-
function test_theme_table(){
    $html = '';
 
    //this $header array contains table header name,can be changed as per the requirement
    $header = array(t('BID'),t('Module'),t('Delta'),t('THEME'),t('Status'));
 
    //$count is the number of rows you want to display per page
    $count = 5;                   
   
    //fetching records from blocks tabble
    $res = "SELECT * FROM {blocks}";
    
   //passing sql query and count value in drupal pager_query function
    $query = pager_query($res, $count);
    $data = array();
    while ($row = db_fetch_array($query)) {
      $data[] = array(
                      $row['bid'],
                      $row['module'],
                      $row['delta'],
                      $row['theme'],
                      $row['status']
                      );
    }
    //adding id to the table(Not required)
    $table_attributes = array('id' => 'example');
    $output = theme('table', $header, $data, $table_attributes);
 
    //returning the resultant table with $count=5
return $output.theme('pager', $count);
}
Instead of displaying records from database,you can display any records using them table.
  

How to create date popup in drupal custom module?

This is one of the most common feature that we need to implement in any project.

Here I am giving the step by step explanation with code.

1:- First download the date module from drupal.org.
2:-Enable the date & date popup module.
3:-Now go to your .module file (inside your custom module folder) then in hook_form function, and give #type=>date_popup.

Here is the code for the reference:-
        $format='d-m-Y';
        $form['date'] = array(
                '#type' => 'date_popup', //this is the main line of code that need to be add
                '#title' => t('Date'),
                '#date_format' => $format, //this date format can be changed as per the requirment
       );