Help with a custom field widget I am trying to create a custom field widget to be used by the taxonomy term reference field.
Basically I would like to select which taxonomy terms can be shown in the select list.

So far I am able to register the widget along with a custom settings page but when I use the widget on a node edit form. The values are not saved.

Here is the code below I have implemented a hook_widget_info hook_widget_settings_form and hook_field_widget_form from my understanding those three hooks should be enough

function my_module_field_widget_info() {
  return array(
    'my_module_term_reference_limit' =&gt; array(
      'label' =&gt; t('my module Term reference select'),
      'field types' =&gt; array('taxonomy_term_reference'),
      'description' =&gt; t('Allows you to limit the number of terms allowed in a select list'),
    ),
    'settings' =&gt; array(
        'terms' =&gt; array(),
      ),
  );
}



function my_module_utils_field_widget_settings_form($field, $instance) {
  $widget = $instance['widget'];
  $settings = $widget['settings'];
  $vocabulary = taxonomy_vocabulary_machine_name_load($field['settings']['allowed_values'][0]['vocabulary']);
  $type = $instance['widget']['type'];
  $terms = taxonomy_get_tree($vocabulary-&gt;vid);
  $options = array();
  $default_value = array();

  foreach($terms as $key =&gt; $term){
    $options[$term-&gt;name] = t($term-&gt;name);
  }


  $form = array();
  if($instance['widget']['type'] == 'my_module_term_reference_limit') {
    $form['terms'] = array(
      '#type' =&gt; 'checkboxes',
      '#title' =&gt; t('My module terms'),
      '#options' =&gt; $options,

      '#description' =&gt; t('Select compatible templates'),
  );
}
  return $form;
}


function my_module_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $settings = $instance['widget']['settings'];

 $type = $instance['widget']['type'];

  $options = array();
  foreach($settings['terms'] as $key =&gt; $value){
    if($value !== 0){
     $options[$value] = t($value);
   } 
 }

$widget = $element;

  switch ($instance['widget']['type']) {
    case 'ii_term_reference_limit':
      $field['cardinality'] = 1;
      $widget += array(
       '#title' =&gt; t('my term select box'),
       '#type' =&gt; 'select' ,
       '#options' =&gt; $options,

  );
      break;
  }

  $element +=  $widget;
  return $element;

}


Thank you for your help
Looks like you're just missing the column name for the field (tid).

Just before the return of the widget form function, try changing

$element +=  $widget;


to

$element['tid'] = $widget;