field widget is not saving selected value to database I am creating a widget under taxonomy_term_reference field and trying to use the same autocomplete used by taxonomy module, autocomplete is working fine but data is not getting saved.

    /**
     * Implements hook_field_widget_info().
     */
    function test_field_widget_info() {
      return array(
        'test_widget' =&gt; array(
          'label' =&gt; t('test Engine'),
          'field types' =&gt; array('taxonomy_term_reference'),
          'settings' =&gt; array(
            'size' =&gt; 60,
            'autocomplete_path' =&gt; 'taxonomy/autocomplete',
          ),
          'behaviors' =&gt; array(
            'multiple values' =&gt; FIELD_BEHAVIOR_CUSTOM,
          ),
        ),
      );
    }

    /**
     * Implements hook_field_widget_form().
     */
    function test_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {
      if ($instance['widget']['type'] == 'test_widget') {
        $form_field = array();
        $tags = array();
        foreach ($items as $item) {
          $tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']);
        }
        $form_field['autocomplete'] = array(
          '#type' =&gt; 'textfield',
          '#title' =&gt; 'Tags',
          '#default_value' =&gt; taxonomy_implode_tags($tags),
          '#autocomplete_path' =&gt; 'taxonomy/autocomplete' . '/' . $field['field_name'], // Trying to use the same autocomplete path from taxonomy module.
          '#size' =&gt; $instance['widget']['settings']['size'],
          '#maxlength' =&gt; 1024,
          '#element_validate' =&gt; array('test_validate'),
          '#attributes' =&gt; array(
            'class' =&gt; array($element['#field_name']),
          ),
        );

        $form_field['search'] = array(
          '#type' =&gt; 'button',
          '#value' =&gt; t('Search Tags'),
          '#ajax' =&gt; array(
            'callback' =&gt; '_test_callback',
          ),
          '#attributes' =&gt; array(
            'reference_class' =&gt; $element['#field_name'],
          ),
          '#name' =&gt; $element['#field_name'],
        );
        $element += $form_field;
        return array('tid' =&gt; $element);
      }
    }
function test_validate($element, &amp;$form_state, $form) {
  $value = array();
  if ($tags = $element['#value']) {
    // Collect candidate vocabularies.
    $field = field_widget_field($element, $form_state);

    $vocabularies = array();
    foreach ($field['settings']['allowed_values'] as $tree) {
      if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
        $vocabularies[$vocabulary-&gt;vid] = $vocabulary;
      }
    }
  }
  $typed_terms = drupal_explode_tags($tags);
  foreach ($typed_terms as $typed_term) {
    // See if the term exists in the chosen vocabulary and return the tid;
    // otherwise, create a new 'autocreate' term for insert/update.
    if ($possibilities = taxonomy_term_load_multiple(array(), array('name' =&gt; trim($typed_term), 'vid' =&gt; array_keys($vocabularies)))) {
      $term = array_pop($possibilities);
    }
    else {
      $vocabulary = reset($vocabularies);
      $term = array(
        'tid' =&gt; 'autocreate',
        'vid' =&gt; $vocabulary-&gt;vid,
        'name' =&gt; $typed_term,
        'vocabulary_machine_name' =&gt; $vocabulary-&gt;machine_name,
      );
    }
    $value[] = (array)$term;
  }
  form_set_value($element, $value, $form_state);
}
Try adding the following line below form_set_value().

$element['#value'] = 'new_value';


P.S. Borrowed from Alter taxonomy autocomplete value