AJAX error on form alter I have a form alter function, it seems working fine, but, i am getting this strange error, i am not able to figure this out. Please help me out. I have a dependent dropdown. I am pulling 1st level vacabulory in 1st dropdown. 2nd dropdown is basically the childrens of the parent chosen from the 1st dropdown. The code works, but give me error.

function teacher_form_alter(&amp;$form, &amp;$form_state, $form_id){

  if($form_id == "teacher_profile_node_form"){

        $form['field_teacher_city'] = array (
           '#title'   =&gt; 'City',
           '#type'    =&gt; 'select',
           '#options' =&gt; _teacher_city_options_list_taxonomy(),
           '#ajax'    =&gt; array(
                'event'=&gt;'change',
                'callback' =&gt;'_teacher_location_list_dropdown',
                'wrapper' =&gt; 'edit-field-city',
                'method' =&gt; 'replace',
                )
          );

      $form['field_teacher_locations'] = array(
           '#title'   =&gt; 'Location',
           '#type'   =&gt; 'select',
           '#options' =&gt; get_dropdown_list(),
           '#prefix' =&gt; '&lt;div id="edit-field-city"&gt;',
           '#suffix' =&gt; '&lt;/div&gt;',

       );
     }

    return $form;
}

function get_dropdown_list() {

      $options2 = array(
        0 =&gt; t('Zero'), 
        1 =&gt; t('One'), 
        2 =&gt; t('Two'), 
        3 =&gt; t('Three'),
           );

return $options2;
}

function _teacher_location_list_dropdown($form, $form_state)  {
  // use this method to populate the demo list from the list of courses
  $vocab = taxonomy_vocabulary_machine_name_load('locations');

  $vid = $vocab-&gt;vid;

  $sel = $form_state['values']['field_teacher_city'];
  drupal_set_message($sel);

  if (!isset($sel)) {

      $options = array(
        0 =&gt; t('four'), 
        1 =&gt; t('five'), 
        2 =&gt; t('six'), 
        3 =&gt; t('seven'),
           );

  }
  else {
      $terms = taxonomy_get_tree($vid,$sel,1,FALSE);

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

  $form['field_teacher_locations']['#options'] = $options;

  return   $form['field_teacher_locations'];
;
}


Error is below

Warning: array_values() expects parameter 1 to be array, string given in _field_filter_items() (line 515 of C:\wamp\www\drupal-7.19\modules\field\field.module).
Warning: Invalid argument supplied for foreach() in list_field_validate() (line 392 of C:\wamp\www\drupal-7.19\modules\field\modules\list\list.module).
You're not supposed to change the $form element in the AJAX callback, only in the form_alter function. Otherwise,


  when the form is submitted (ajax or not), the submitted form does not
  match the cached form, which causes Drupal to fail