Thursday, August 28, 2008

Firefox 3 move tabs to bottom

Ok you were using firefox 2.0 with tab preferences extension. You had set the tabs to appear on the bottom. You upgraded your ff to 3.x. Now tab preferences extension anymore. There seems to be no easy way to move tabs to the bottom.

Or is there one?

There is. Just install Tab mix plus extension from mozilla addon site. There are lot of options for tabs, including moving it to bottom and undo closed tabs. It works with versions 1.0-3.0a5.

What about 3.0.1? Am I out of luck?

No. There is a dev version available in the author's website. You can find it here. Check the mozilla tab mix plus extension page before you install dev version. You might find a version released for 3.0.1 soon.

Friday, August 22, 2008

Programmatically create drupal term

Ever wanted to programmatically create drupal term? Here is the code snippet. Just call the below function by passing vocabulary id under which you want to create term.

function term_create($vid)
$edit = array ("vid" => $vid, "name" => $term_name);

Of course, you have to run this in a drupal environment, which means that you should have bootstrapped drupal before using the above function.

One issue with the above function is it uses vocabulary id, which we don't have/know most of the time. There is a quick solution. You can use below function to get vocabulary id from name.

function get_vocabulary_id ($vname)
$results = db_query('SELECT * FROM {vocabulary} WHERE name = "%s"', $vname);
return $res->vid;
return null;

About drupal categories and subcategories

Drupal has an excellent way of classifying data. You can create a classification tree structures of whatever depth you want and arrange your data in the structures.

The problem: In the administration panel, you never see anything like classifications or categories.

Well, drupal calls it in a different name.

The root node of such structure is called vocabulary. The child nodes are called terms.

Administration (create/edit/update) of vocabulary and terms are available under Taxonomy.

Wednesday, August 13, 2008

Using date field in drupal forms

Adding a date field into drupal form is very easy. Just declare the form element to be of type 'date'. It automatically presents dropdowns for day, month and year next to each other neatly.


$form['date_of_birth'] = array(

'#type' => 'date',

'#title' => t('Date of Birth'),

'#default_value' => $node->expiry_date,

'#description' => t('Date of Birth')


Now we have the date field in our form. All is well till now -- until we submit the form.

Usually we use $form_values['values']['<field_name>'] to get the value and insert into the database. When we try to use the above value in the database INSERT INTO statement, it gives an error or does not insert the value.

So what is the problem? Actually $form_values['values']['date_of_birth'] is not a regular date string, but is an array containing day, month and year. So you have to create date string using the array before inserting into the database.

Here is an example to create a string suitable to insert into MySql date field:


Now you can use the $date_of_birth_str in the INSERT INTO statement.