Form select option results in "Illegal Choice has been detected" I have a form where a user picks a date for their submission(s) to appear on the website. I am populating a 'date' field like so:

function mymodule_get_date_options($type = 'start') {
  $options = array();

  $start_week = time();

  if (date('w', $start_week) == 3) {
    $start_week = strtotime('+1 week', $start_week);
  }

  while (date('w', $start_week) != 3) {
    $start_week = strtotime('+1 day', $start_week);
  }

  if ($type == 'end') {
    $start_week = strtotime('+1 week', $start_week);
  }

  for ($x = 0; $x &lt; 24; $x++) {
    $options[date('U', $start_week)] = date('M d, Y', $start_week);
    $start_week = strtotime('+1 week', $start_week);
  }

  return $options;
}


And the element:

$form['start_date'] = array(
    '#title' =&gt; t('Start Date'),
    '#type' =&gt; 'select',
    '#options' =&gt; mymodule_get_date_options('start'),
    '#default_value' =&gt; $mymodule_form_object-&gt;start_date,
  );


The generated HTML:

// a chunk of the option elements
&lt;option value="1313615248"&gt;Aug 17, 2011&lt;/option&gt;
&lt;option value="1314220048"&gt;Aug 24, 2011&lt;/option&gt;
&lt;option value="1314824848"&gt;Aug 31, 2011&lt;/option&gt;
&lt;option value="1315429648"&gt;Sep 07, 2011&lt;/option&gt;
&lt;option value="1316034448"&gt;Sep 14, 2011&lt;/option&gt;
&lt;option value="1316639248"&gt;Sep 21, 2011&lt;/option&gt;
&lt;option value="1317244048"&gt;Sep 28, 2011&lt;/option&gt;
&lt;option value="1317848848"&gt;Oct 05, 2011&lt;/option&gt;
&lt;option value="1318453648"&gt;Oct 12, 2011&lt;/option&gt;


So, everything looks okay, except when the form is submitted it says 'An Illegal Choice has been detected" with the date selects highlighted.
That's because the form gets generated both upon output and submission, and you're using form values that are time-dependent. When you first output the form it generates options like this:

1313615248
1314220048
1314824848
1315429648


And when a user submits the form, it will generate new values, with a few second difference:

1313615268
1314220068
1314824868
1315429668
(+20 second difference)


So none of the previous options are present here. Drupal's validator by default checks if the submitted option is among generated options.