field_get_items / value when creating new content I think I am about to lose my mind .. how in earths name do I get the value of a field in a widget during creation? I created a custom field widget, and during creation of new content I want to be able to do the following:

I want to create a custom field that I can attach to any content type. This custom field has two elements, a textfield to search for products in MySQL. And a selectbox. The selextbox should get filled with options that match the letters that the user types in the textfield.

I checked field_get_items and a lot more, but I just cannot get it. The code below has elements from a form that I made, so please just overlook those parts. I used DPM($something); everywhere trying to see if I can see the value of $element['searchfield'] anywhere ..

$items = field_get_items('node', $node, 'searchfield'); .. doesnt work, but from what I understand this is only to be used after the node is created .. ie to retrieve the added values, I NEED the values during runtime ...

/**
* Implements hook_field_widget_form().
*/
function field_zoekproduct_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch ($instance['widget']['type']) {
    case 'field_zoekproduct_field' :

      $element['searchfield'] = array(
        '#title' =&gt; t('Zoek naar een product'),
        '#type' =&gt; 'textfield',
        '#maxlength' =&gt; 115,
        '#size' =&gt; 55,
        '#weight' =&gt; 0,
'#default_value' =&gt; 'zoek...',
'#attributes' =&gt; array('onfocus' =&gt; "this.value = '';"),  //when textbox gets focus the default value will be removed
'#ajax' =&gt; array(
  'event' =&gt; 'change',
  'callback' =&gt; 'zoekproduct_zoek_getypte_text',
  'keypress' =&gt; true,
  //'effect' =&gt; 'fade',
  'wrapper' =&gt; 'dropdown-second-replace',
),
    );


// with the piece of code below in a form module I can get the value of the textfield in $selected and
therefor am able to fill my select with options from the database that match $selected .. now How do I do the same with a custom field????

$options_first = zoekproduct_maak_een_eerste_selectie();
$selected = isset($form_state['values']['searchfield']) ? $form_state['values']['searchfield'] : key($options_first);

$element['overzicht_producten'] = array(
'#type' =&gt; 'select',
'#title' =&gt; t('Overzicht producten'),
'#prefix' =&gt; '&lt;div id="dropdown-second-replace"&gt;',
'#suffix' =&gt; '&lt;/div&gt;',
'#size'=&gt;1,
'#validated' =&gt; TRUE,
'#options' =&gt; zoekproduct_zoek_naar_getypte_text($selected),
'#default_value' =&gt; isset($item['overzicht_producten']) ? $item['overzicht_producten'] : '',
'#ajax' =&gt; array(
  'event' =&gt; 'change',
  'callback' =&gt; 'zoekproductfield_selecteer_product',
  'wrapper' =&gt; 'find_product',
),
);

      break;
  }
  return $element;
}
One option would be to take advantage of states (see states and/or forms reference).

Here is an example... It's by no means perfect but hopefully it will give you an idea of how states work:

$options_1 = array('Option A', 'Option B', 'Option C');
$options_2 = array('Option D', 'Option E', 'Option F');
$element['overzicht_producten'][] = array(
  '#type' =&gt; 'select',
  '#title' =&gt; t('Overzicht producten'),
  '#options' =&gt; $options_1,
  '#states' =&gt; array(
    'visible' =&gt; array(
      // To make this select menu visible, type "Visible1" (no quotes) into the "searchfield" box.
      ':input[name="searchfield"]' =&gt; array('value' =&gt; 'Visible1'),
    ),
  ),
);
$element['overzicht_producten'][] = array(
  '#type' =&gt; 'select',
  '#title' =&gt; t('Overzicht producten'),
  '#options' =&gt; $options_2,
  '#states' =&gt; array(
    'visible' =&gt; array(
      // To make this select menu visible, type "Visible2" (no quotes) into the "searchfield" box.
      ':input[name="searchfield"]' =&gt; array('value' =&gt; 'Visible2'),
    ),
  ),
);


Hope that helps... :)