Value from ajaxified form field not passed to ajax callback This is a continuation of this issue, where I couldn't get the ajax to fire on an entity reference field in a node edit form. With the following code, I'm able to get the ajax to fire.

/**
 * Implementation of hook_form_FORM_ID_alter()
 */
function mymodule_form_blog_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['field_video_reference']['#ajax'] = array(
    'callback' =&gt; 'mymodule_video_ajax_callback',
    'wrapper' =&gt; 'my-path-div',
  );

  $form['my_path'] = array(
    '#markup' =&gt; t('My path'),
    '#prefix' =&gt; '&lt;div id="my-path-div"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#weight' =&gt; 6,
  );

  if (!empty($form_state['values']['field_video_reference']['und'][0]['target_id'])) {
    $form['my_path']['#markup'] = 'Token path: http://www.mysite.org/node/' . $form_state['node']-&gt;field_video_reference['und'][0]['target_id'];
  }
}

function mymodule_video_ajax_callback($form, $form_state) {
  return $form['my_path'];
}


The problem is that the value from field_video_reference isn't being passed to the if statement in the form builder or my callback, so the value from that field isn't displayed in the my_path field when the value is first selected on the node create form (it works fine if the node has already been saved and there is a value in field_video_reference when I edit the node). I'm following examples from the "Drupal 7 Module Development" book as well as from the Examples module, so I can't see what I'm missing.

Thanks.
$form_state['values']['field_video_reference']['und'][0]['target_id'] looks wrong to me.

I would expect the value to be in $form_state['values']['field_video_reference'].

If you haven't already then install the Devel module and then use can use dpm($form_state); to output the array to the message area and inspect it to find the correct path.

Sometimes for ajax requests Devel Debug Log is also useful as it allows you to send a dump of a variable to a log so you can inspect it even if it is not possible to send content to the message area.