Autocomplete textfield in Drupal.

Dear Friends, Last week I got a chance to work on drupal and had to add autocomplete functionality to textfields. I had to fetch/search data from database and show in text field.

Example: Suppose I want to make autocomplete text field for ‘author’ table:

CREATE TABLE `author` (
  `first_name` varchar(100) NOT NULL,
  `last_name` varchar(100) DEFAULT NULL,

Steps to achieve this are:

1. Create a menu hook in your .module file as below:

$items['search/get_author'] = array(
   'title'  => 'text matching',
   'page callback'  => 'author_autocomplete',
   'access arguments' => array('view keyword autocomplete'),
   'type'  => MENU_CALLBACK,

Here we are using existing search functionality.

2. Create function that we call for search from database as below:

function author_autocomplete($string='') {
  $matches = array();
   if($string) {
     $result = db_query_range("SELECT * FROM {author} WHERE first_name LIKE '%s%%' OR last_name LIKE '%s%%'", array($string, $string), 0,     variable_get('keyword_autocomplete_matches', 10));
       while ($data = db_fetch_object($result)) {
         $matches[$data->first_name . ' '. $data->last_name] = check_plain($data->first_name) . ' ' .check_plain($data->last_name);

3. Now create a textfiled with ‘autocomplete_path’ parameter using Drupal form API as below:

$form['Author'] = array(
  '#type' => 'textfield',
  '#title' => t('Author'),
  '#default_value' => $object['Author'],
  '#size' => 60,
  '#maxlength' => 64,
  '#autocomplete_path' => 'search/get_author',

Now, Let me explain the concept how it works.

When you type something to Author textfield autocomplete_path callback the ‘search/get_author’ -> Drupal menu hook look for page callback function ‘author_autocomplete’  -> Now function author_autocomplete generate the drupal_json data to autocmplete.js which is automatically included when you work under ‘search’ module.

Hope this will help new drupal developers and some experienced who did not work on this functionality.

Thanks and Regards,

Mahesh Salaria

Windows 7

I just finished testing of Windows 7 on my laptop (Acer Aspire 4520). It runs flawlessly and much better than Vista. Everything is very neat and clean and easy to access.

Lots of improvements in Task bar and other parts of Windows access. Main thing lots of people concerned about performance on Windows Media Center and its very much improved than Vista, You can feel the effects of Zune with it 😉

Windows media player is also improved and optimized to use low memory.

To know about more changes and improvements check on Microsoft Web Site

Here are some screen shots of Windows 7:

But Windows 7 crashes some of the applications and I reported them to Microsoft and I’m Sure they will fix them in Stable build and we are looking for more stable and smooth build.

Credits to Microsoft who provide us rock solid Operating System year after year. 😉

Live Example of Distributed Computing (World Community Grid)

World Community Grid’s mission is to create the largest public computing grid benefiting humanity. Our work is built on the belief that technological innovation combined with visionary scientific research and large-scale volunteerism can change our world for the better. Our success depends on individuals – like us – collectively contributing their unused computer time to this not-for-profit endeavor.

I’m also contributing to this community and my computer is generating good results to help humanity. I proud to be a part of this project and will continue my services on this community.

You can also join the World Community Grid by clicking following link or directly from their website


At the end of the year I bought a new NetBook Asus EEE PC 1000H for portability.

Asus Eee pc 1000h

Usually I travel to different location on weekends and always I have to carry my 14.1″ Laptop with an extra bag and Its battery lasts within 2hrs. So, I planned to buy this NetBook as its battery backup is 7hrs (One day Computing).

Here you can find specifications

I tested this netbook for a day and battery lasts at 5Hrs and 50Min, Not bad as I did lot of testing 😉

I installed Ubuntu eee on this and now it has dual boot with preinstalled Windows XP. Both OS runs flawlessly.

Asus 1000H is a Gadget of the year 2008 and Asus EEE PC is getting matured with launch of this product. Great work done by ASUS 🙂

iPod Touch 8Gb

I bought iPod Touch 8Gb this month but not got time to post on my blog.


Here you can find its specification

I liked its mutitouch functionality and applications developed by other developers. I tested several Paid and free application and every application adds a new functionality to my iPod.

My Favorite Games on iPod are “Space Deadbeef”, “Audi A4”, “FS5 Hockey” and “Darts”.

My Favorite Applications are “Free RSS”, “To Do’s” and “WebDAV Files Lite”.

Mostly I use “WebDAV File Lite”, By using this application you can upload your PDF, DOC, PPS etc files to your iPod and read them on your device. Thanks to original development team 🙂