I have a problem with getting my module_form_alter to work for hierarchical select. I am running on Drupal 7 and my content type is called mytemp and I'm pretty sure my form-id is mytemp_node_form. I have a taxonomy called ICA which my hierarchical select references to.

I get the following error when I run it:

Warning: Invalid argument supplied for foreach() in arjmod_form_alter() (line 8 of /var/www/hcms/sites/all/modules/arjmod/arjmod.module)

I would like to have my hierarchical select appear with a fixed row height but I can't get it to work.

This is my code:

function mymodule_form_alter (&$form, &$form_state, $form_id){
  if($form_id == 'mytemp_node_form'){
    foreach ($form['taxonomy'] as &$vocab)
      if($vocab['#type'] == 'hierarchical_select')
        $vocab['#size'] = 10;
}} ?>

Please point me in the right direction.

  • I just used hierarchical select in a custom form the other week. Why are you using a form alter on a node form? Why not just configure the field's widget settings using the hierarchical select widget? Do you have the hierarchical select's taxonomy submodule enabled?
    – Jason
    Commented Apr 29, 2014 at 3:41

2 Answers 2


Looks like $form['taxonomy'] is not an array.

There are some options for hierarchical selects maybe this is all you need:


  • Thanks man, i'll check it out and update the post if i get it to work.
    – vaeros
    Commented Jun 18, 2012 at 3:03

I think you need to assign taxonomy to a variable, and $vocab shouldn't be passed byref:

$taxonomy = $form['taxonomy'];
foreach ($taxonomy as $vocab) {...}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.