"Illegal Choice has been detected" I am dynamically populating &lt;select&gt; throught javascript in Drupal 7. The system gives me an error on submit:

"Illegal Choice has been detected"

How to mark, that this &lt;select&gt; must skip this error?
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.