User Profiles On Registrations - Per Role


Dear Dhongis,

We have almost all sites where we have multiple roles and we need a different profile for each role. This was so far rocket science since we did not have a mechanism to create different looking registration forms per user role. We handled this situation post login when we asked people to create profiles as per their roles.

Also, we have an issue of assigning roles when logically a person should be able to choose their role and admins should simple approve or disapprove of it.

Walking by the PC
One September Afternoon
I found the solution
But not very soon

How to send email from loclahost Drupal hosted in Ubuntu?


Consider a situation in which you have installed Drupal in your Ubuntu machine. Now you would like to start sending email from localhost.If you have not setup Mail Transfer Agent(MTA) than you will not be able to send email from localhost.

What is Mail Transfer Agent(MTA)?

Wikipedia Says:

Utility Methods


function_exists: function_exists — Return TRUE if the given function has been defined


bool function_exists ( string $function_name )


if (function_exists('payroll_getcomponents')) {
"payroll_getcomponents functions is available");
"payroll_getcomponents functions is NOT available");

profile2_load_by_user: Loads the profile data of a user. Takes user id as input


profile2_load_by_user($account, $type_name = NULL)


How to Set Filters for a View in Drupal 7 programmatically


Accessing a view programmatically

$view = views_get_view('view_name');
$view->set_display('default'); // or display id like page_1, block_1
//display_name = 'default' or 'page' and so on
//filter_name is the name of the filter

Google Drive for Project Management

This post highlights the important features Google has brought into it's Drive tool (formerly Google Docs and Spreadsheets) which has made online collaboration easier than before and enabled the use of Spreadsheets as a serious project management tool.

Without going into obvious features, what I would like to highlight is the fact that Google Drive not supports Pivoted spreadsheets. This means that while you maintain your raw data, you can also auto generate elegant status reports with all the power of pivots. An example report for one of my active project is here:

Inspecting Objects: Simple Trick


How often have you felt the need to display a PHP Object in a readable manner? We are all very familiar with the use of the print_r() function. However, print_r() gives a difficult to read output and we end up matching braces to figure out the exact structure of complex objects. Here is a small trick which you can use to see the print_r() output in a 'Display for Humans' format.

echo '<pre>';
echo '</pre>';

Let's see an example(borrowed from


Creating a Drupal 7 Node Programmatically

* Basic Node Creation Example for Drupal 7
* This example:
* - Assumes a standard Drupal 7 installation
* - Does not verify that the field values are correct
$body_text = 'This is the body text I want entered with the node.';

$node = new stdClass();
$node->type = 'article';
node_object_prepare($node); //Creates default settings for the node of a type
$node->title = 'Node Created Programmatically on ' . date('c');
$node->language = LANGUAGE_NONE; //String constant value for "und"

/* If u have body text do the following below

Add Sites to search in Apache Multicore Configurations

Solr is the popular, blazing fast open source enterprise search platform from the Apache Lucene project. Its major features include powerful full-text search, hit highlighting, faceted search, dynamic clustering, database integration, rich document (e.g., Word, PDF) handling, and geospatial search. Solr is highly scalable, providing distributed search and index replication, and it powers the search and navigation features of many of the world's largest internet sites.

Dates using PHP


Time and again date parsing issue comes up and I find myself looking all over the net for finding ways to do the same. This post is created to compile all such ways as I encounter:

Parsing Dates

If your date format is: yyyy-mm-dd, you can simply use strtotime and date function to get the desired date format

$data[] = date( 'd-m-Y', strtotime('2012-03-21')); //get the format as 21-03-2012

Get Dates Using Strotime
strtotime can recognize certain keywords.
echo strtotime('now');
echo strtotime('+4 days');

Extract Result Data From Drupal View


The code to do the trick is provided below:

= views_get_view('view_name');
$view->set_display('default'); // or display id like page_1, block_1
    //$view->set_arguments(array(arg(0),'arg_data2'));  // 2nd  Argument
drupal_set_message("Field data value: ".$view->result[0]->node_data_field_as_it_appears_in_views_query_sql);

Update for Drupal 7: