Drupal 6, avoiding message ‘An illegal choice has been detected’.

Drupal form control can be tiresome some times, especially when developping custom modules .. In my case it was the integration of country and region select boxes from the ubercart module.

In my implementation of hook_form_alter we are adding these two elements in code :

$select_country = uc_country_select(uc_get_field_name('country'), $country, NULL, 'name');
$select_zone = uc_zone_select(uc_get_field_name('zone'), $zone, NULL, $country, 'name');

$form['country'] = $select_country;
$form['zone'] = $select_zone;

But when submitting the form we have always the same error : An illegal choice has been detected ??!!

As a solution and reading validation from code it’s possible to add in the form alter the information that this form has been already validated :

$form['zone']['#validated'] = true;

Drupal 6, programtically add custom meta tags to pages

Assuming that we need to add custom meta tags by page url or node type, drupal hook_preprocess_page() is the last function called before displaying the page, so it’s the right place for doing that :

 * Implementation of hook preprocess_page
 * @param array $variables
function my_module_preprocess_page(&$variables) {
    //using path
    if(arg(1) == 'gallery'){
      //load existing node
      $node = node_load(arg(2));
     // the meta content.
      $head = ' .. ';
      $variables['head'] = drupal_get_html_head();

In this case path is : gallery/[nid]