Populate a select box with a vocabulary I have a select box that I want to populate with a particular taxonomy programmatically. If i was was to use a taxonomy vocabulary how would i populate a particular select box in my form. My form is generated using the from api and not using content types. If for example I was to have a vocabulary called countries. I have a select box which currently is configured like this

 $form['status']['currentstatus'] = array (
 '#values' =&gt; array(t('red'), ('green'))


 );


$form['status']['currentStatusList'] = array (
    '#title' =&gt; 'current status',
    '#type' =&gt; 'select',
    '#options' =&gt; $form['status']['currentstatus']['#values']    
);


Instead of just adding the values I would like to pass a vocabulary.

I have manged to get the vocabulary data 
but a zero is placed before the terms.



the code I figured out for the box is the same as yours. I even pass the id for the vocabulary. I will have a play with it thanks for your help
You should be able to use the taxonomy_get_tree function to get all the children of the term, and then just run a foreach() on that.

Example:

function mymodule_blah($vocabulary) {
  $terms = taxonomy_get_tree($vocabulary);

  foreach ($terms as $data) {
    $output[$data-&gt;tid] = $data-&gt;name;
  }

  return $output;
}


This should return an array keyed by Term ID, although you could put whatever you want where it says $data['tid'] to put a different key in.

Example output:

[1] =&gt; ['My First Term']
[2] =&gt; ['My Second Term']
...
[15] =&gt; ['My Fifteenth Term']


Then pass this to your '#options' on your select box.

EDIT:

Forgot to mention that the helper function will need the vocabulary ID passed to it - should have added in the clarification just for completeness' sake.

EDIT 2 (full implementation):

function mymodule_myform($form) {
//The rest of your form stuff is in here
$form['status']['currentStatusList'] = array (
    '#title' =&gt; 'current status',
    '#type' =&gt; 'select',
    '#options' =&gt; mymodule_selectbox_contents(PUT THE NUMERIC VOCABULARY ID HERE)    ,
);
//The rest of your form stuff is in here
}

function mymodule_selectbox_contents($vid) {
  $terms = taxonomy_get_tree($vid);

  foreach ($terms as $data) {
    $output[$data-&gt;tid] = $data-&gt;name;
  }

  return $output;
}