"Illegal Choice has been detected"
To solve the problem set '#validated' => 'TRUE' in your form element definition.

Example:
 form['my_dynamic_select'] = array(
 … 
 '#type' =&gt; 'select',
 '#validated' =&gt; TRUE
 …
 )


Reason:

If we are using a dynamically populated SELECT (dropdown) via AJAX this error will pop up. When a value is not present in options array, Drupal will consider it as illegal. So the user couldn't inject an illegal value into the database. 

But in our case it's totally ok, so we need to use the attribute 'validated' =&gt; TRUE to skip the validation.

Source: An illegal choice has been detected. Please contact the site administrator.