How can I place a  new  textfield in the tab vocabularies in a content type? I want to place a new text field in the "Vocabularies" field set of a node; the text field is not tag. 

I am using the Vertical Tabs module, and my fields in the content type are in group.

The following is the structure of my content type:


Title
Vocabularies (taxonomy) -> Here I want to place a field too.
fieldset1 (Fields:  field1, field2, and field3)
fieldset2 (Fields: field4, field5)
The fieldset for the vocabularies used by a node are added from taxonomy_form_alter(), using the following code (the relevant part is the one between "// 3" and "// 4"):

// 1
if (!isset($node-&gt;taxonomy)) {
  $terms = empty($node-&gt;nid) ? array() : taxonomy_node_get_terms($node);
}
else {
  // After a preview or form reload, the terms must be converted to objects.
  reset($node-&gt;taxonomy);
  if (!is_object(current($node-&gt;taxonomy))) {
    $node-&gt;taxonomy = taxonomy_preview_terms($node);
  }
  $terms = $node-&gt;taxonomy;
}

$c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $node-&gt;type);

while ($vocabulary = db_fetch_object($c)) {
  if ($vocabulary-&gt;tags) {
    if (isset($form_state['node_preview'])) {
      // Typed string can be changed by the user before preview,
      // so we just insert the tags directly as provided in the form.
      $typed_string = $node-&gt;taxonomy['tags'][$vocabulary-&gt;vid];
    }
    else {
      $typed_string = taxonomy_implode_tags($terms, $vocabulary-&gt;vid) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary-&gt;vid] : NULL);
    }
// 2
    if ($vocabulary-&gt;help) {
      $help = filter_xss_admin($vocabulary-&gt;help);
    }
    else {
      $help = t('A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".');
    }
    $form['taxonomy']['tags'][$vocabulary-&gt;vid] = array(
      '#type' =&gt; 'textfield', 
      '#title' =&gt; $vocabulary-&gt;name, 
      '#description' =&gt; $help, 
      '#required' =&gt; $vocabulary-&gt;required, 
      '#default_value' =&gt; $typed_string, 
      '#autocomplete_path' =&gt; 'taxonomy/autocomplete/' . $vocabulary-&gt;vid, 
      '#weight' =&gt; $vocabulary-&gt;weight, 
      '#maxlength' =&gt; 1024,
    );
  }
  else {
    // Extract terms belonging to the vocabulary in question.
    $default_terms = array();
    foreach ($terms as $term) {
      // Free tagging has no default terms and also no vid after preview.
      if (isset($term-&gt;vid) &amp;&amp; $term-&gt;vid == $vocabulary-&gt;vid) {
        $default_terms[$term-&gt;tid] = $term;
      }
    }

// 3
    $form['taxonomy'][$vocabulary-&gt;vid] = taxonomy_form($vocabulary-&gt;vid, array_keys($default_terms), filter_xss_admin($vocabulary-&gt;help));
    $form['taxonomy'][$vocabulary-&gt;vid]['#weight'] = $vocabulary-&gt;weight;
    $form['taxonomy'][$vocabulary-&gt;vid]['#required'] = $vocabulary-&gt;required;
  }
}
if (!empty($form['taxonomy']) &amp;&amp; is_array($form['taxonomy'])) {
  if (count($form['taxonomy']) &gt; 1) {
    // Add fieldset only if form has more than 1 element.
    $form['taxonomy'] += array(
      '#type' =&gt; 'fieldset', 
      '#title' =&gt; t('Vocabularies'), 
      '#collapsible' =&gt; TRUE, 
      '#collapsed' =&gt; FALSE,
    );
  }
  $form['taxonomy']['#weight'] = -3;
  $form['taxonomy']['#tree'] = TRUE;
// 4
}


The fieldset, which is then changed by the Vertical Tabs module in a tab, is added only when there are more than one vocabulary associated with the content type of the node being created.

To add a new field in that fieldset, you should implement hook_form_alter() in a module, and add code similar to the following one:

function mymodule_form_alter(&amp;$form, $form_state, $form_id) {
  if (isset($form['type']) &amp;&amp; isset($form['#node']) &amp;&amp; &amp;&amp; $form['type']['#value'] . '_node_form' == $form_id) {
    if (isset($form['taxonomy']['#type']) &amp;&amp; $form['taxonomy']['#type'] == 'fieldset') {
      // Add your field.
      $form['taxonomy']['mymodule_field] = array(
        // …
      );
    }
  }
}


The module you write should be executed after the Taxonomy module, or the module will not find the fieldset added by the Taxonomy module. The module is executed after the Taxonomy module if it has a name such as TaxonomyAddendum, or if the weight of the module is higher than the weight of the Taxonomy module (10 should be enough).

As for altering the existing fields for the taxonomy terms, you should look at the code between the comments "// 1" and "// 2"; as form is build using the vocabulary ID, as in $form['taxonomy'][$vocabulary-&gt;vid], you need to know it to get all the form fields used for the taxonomy terms. If you want to change the form field for a vocabulary for which you know the ID, then the code is simpler, as you don't need to get all the vocabularies that are associated to the node being edited; that is also true if you want to alter the form field for a vocabulary you know by name. You can use the following code to get a vocabulary object knowing the vocabulary name.

$result = db_fetch_object(db_query(db_rewrite_sql("SELECT v.vid, v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' AND v.name = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $type, $vocabulary_name));


$type is the content type that, in your case, is $form['#node']-&gt;type; $vocabulary_name is the name of the vocabulary.

If you know the vocabulary ID, then you can simply use taxonomy_vocabulary_load() to get the vocabulary object, which you could need to populate the taxonomy term form field.