Tuesday, March 8, 2011

Logging in Drupal 7

 Logging in Drupal 7
 Debugging in Drupal 7

If you are coming from java world .logging is what you are looking for or missing it.


Drupal has inbuilt logging system called watchdog which is enabled by default
Click on Reports->Recent log Messages you will find current log entries.


Next step is in your code just place the below line where you want the logger


watchdog('name of your module as declared in your .info file ', 'some text', array(), WATCHDOG_DEBUG);


bingo you should see a logger in recent log messages

Please leave a comment if you like the article..

Simple Form Example Drupal 7 with Submit

Simple Form Example Drupal Below is the folder structure

















deductibe.info

;$Id$
name = CalculateDeductible
description = CalculateDeductible
package = Drupal 7 Development
core = 7.x
files[] = deductible.module
;dependencies[] = autoload
php = 5.2
 


deductible.module

<?php
//;$Id$

function deductible_menu(){
$items['deductible/calculate']=array(
'title'=>'Calculate Deductible',
'page callback'=>'drupal_get_form',
'page arguments'=>array('deductible_simple_form'),
'access arguments' => array('administer user'),
);
return $items;
}

function deductible_simple_form($form,&$form_submit){
      $form['Make'] = array(
        '#type' => 'textfield',
        '#title' => t('Make'),
          '#cols' => 30,
           '#rows' => 1,
      );
        $form['Model'] = array(
        '#type' => 'textfield',
        '#title' => t('Models'),
          '#cols' => 30,
        '#rows' => 1,
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
       '#submit' => array('deductible_submit'),
     
      );
      return $form;
}

/**
 * Implementation of hook_perm().
 */
function deductible_perm() {
  return array('use save and edit', 'administer save and edit');
}

function deductible_submit($form, &$form_values){
      watchdog('Deductibe', 'deductible', array(), WATCHDOG_DEBUG);
      $message = 'You have submitted the ' /*. $form_id . ' form which contains the following data:<pre>' . print_r($form_values,true) . '</pre>'*/;
      drupal_set_message(t($message));
    }


----------

Now place the folder under drupalinstallation/site/all/modules 
Enable the module from Modules
Now go to http://localhost/deductible/calculate

Check this link
http://harshal-techapps.blogspot.com/2011/03/create-simple-module-in-drupal-7.html