Problem dynamically populating a select field based on the selection of another select field I have seen quite a few questions on here about the "Illegal choice has been detected" error when trying to load a select field with AJAX in Drupal 7. I have not yet been able to find an answer to solve my issue though. I have 3 select boxes Year, Make, and Model. When I select a year the makes populate fine. When I select a Make, I get the Illegal choice detected error and the models do not populate. But if I choose another make everything works fine. Can anyone help me figure out why the first attempt doesn't work? Here is the code that I have

function formblock($form, &amp;$form_state) {
  $form = array();

  $form['year'] = array(
    '#type' =&gt; 'select',
    '#options' =&gt; _load_years(),
    '#ajax' =&gt; array(
      'callback' =&gt; 'formblock_make_loader',
      'wrapper' =&gt; 'make_div',
    ),
  );

  $makes = array('empty' =&gt; 'Select Make',);
  if (isset($form_state['values']['year'])) {
    $makes = drupal_map_assoc(_load_make($form_state['values']['year']));
  }

  $form['make'] = array(
    '#type' =&gt; 'select',
    '#options' =&gt; $makes,
    '#prefix' =&gt; '&lt;div id="make_div"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#ajax' =&gt; array(
      'callback' =&gt; 'formblock_model_loader',
      'wrapper' =&gt; 'model_div',
    ),
  );

  $models = array("empty" =&gt; "No Model");
  if (isset($form_state['values']['make'])) {
    $models = drupal_map_assoc(_load_model($form_state['values']['year'], form_state['values']['make']));
  }

  $form['model'] = array(
    '#type' =&gt; 'select',
    '#options' =&gt; t($models),
    '#prefix' =&gt; '&lt;div id="model_div"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
  );

  if (isset($form_state['values']['make'])) {
    $form['model']['#options'] = _load_model($form_state['values']['year'], $form_state['values']['make']);
  }

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit'),
  );

  return $form;
}

function formblock_make_loader($form, $form_state) {
  // The form has already been submitted and updated. We can return the replaced
  // item as it is.
  return $form['make'];
}

function formblock_model_loader($form, $form_state) {
  return $form['model'];
}

function formblock_submit($form, &amp;$formstate){

}

function _load_years(){
  $thisyear = date('Y');
  $years = array();

  foreach(range(1990, $thisyear) as $year) {
    $years[$year] = $year;
  }
  return $years;  // array
}

function _load_make($year) {
  $makes = array();

  // Make API call and get an array of makes

  return $makes;  // array
}

function _load_model($year, $make) {
  $models = array();

  // Make API call and get an array of models

  return $models;  //array
}
You're wrapping your model select options array in t()

i.e: '#options' =&gt; t($models) vs '#options' =&gt; $models

Try this instead, it might work:

  $form['model'] = array(
    '#type' =&gt; 'select',
    '#options' =&gt; $models,
    '#prefix' =&gt; '&lt;div id="model_div"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
  );