October 2009

Subversion and Project hosting

Developer's Network now offering project hosting with Subversion. Read more

Drupal hook: hook_form_FORM_ID_alter

When there is a need to alter a specific form, we use the form id as the filter and alter the form. Drupal 6.x introduces a new hook, hook_form_FORM_ID_alter. This hook is used when we want to alter a specific form without having to write the if condition to filter the form. Alteration makde in this hook will affect only to that particular form. This is useful when we develop a custom content type or presenting a custom form and we need to alter some the form elements based on some conditions.
hook_form_FORM_ID_alter takes two arguments $form and $form_state, the $form is passed by reference and changes mande to this array will effect the form when rendered. FORM_ID is the id of the form to be altered.

Let take a demo for altering the search form

<?php

Syndicate content

Recent comments

toolbar powered by www.mit3xxx.de