How to add taxonomy term reference field in a custom drupal form
For Drupal 7, the code is something like this, where field_tags is a taxonomy field in the node with widget type autocomplete.      

&lt;?php
   $node=node_load($nid);
    $tags = array();
    foreach ($node-&gt;field_tags['und'] as $item) {
      $tags[$item['tid']] = isset($item['taxonomy_term']) ?  $item['taxonomy_term'] : taxonomy_term_load($item['tid']);
    }
    $form['tags'] = array(
      '#type' =&gt; 'textfield',
      '#default_value' =&gt; taxonomy_implode_tags($tags),
      '#title' =&gt; 'Add Tags',
      '#autocomplete_path' =&gt; 'taxonomy/autocomplete/field_tags',
      '#maxlength' =&gt; 1024,
      '#element_validate' =&gt; array('taxonomy_autocomplete_validate')
    );
?&gt;