How to add taxonomy term reference field in a custom drupal form A menu item is defined with drupal_get_form as callback function and returning the form from call back function. How can I add taxonomy_term_reference field to this form?

$items['files/add'] = array(
      'title' =&gt; 'Add file',
      'description' =&gt; 'Allows users to add files',
      'type' =&gt; MENU_CALLBACK,
      'page callback' =&gt; 'drupal_get_form',
      'page arguments' =&gt; array('mymodule_add_file'),
      'access callback' =&gt; TRUE,
    );
function mymodule_add_file($form, &amp;$form_state) {
    drupal_set_title("Add file");
    $form['mymodule_form'] = array(
      '#type' =&gt; 'fieldset',
      '#tree' =&gt; TRUE,
      '#collapsable' =&gt; FALSE,
      '#title' =&gt; 'Adding file to locker room',
    );

    $form['mymodule_form']['file'] = array(
      '#type' =&gt; 'managed_file',
      '#title' =&gt; 'Upload file',      
    );

    $form['mymodule_form']['tag'] = array(
      '#type' =&gt; 'taxonomy_term_reference',
      '#title' =&gt; 'Tags',
    );  

    return $form;
}


I am not sure how to add taxonomy_term_reference field for $form['mymodule_form']['tag'] . I want this field to be a text field with auto complete from a vocabulary terms and new term to be added when entered term is not found
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;