Hi,
I used Active Select module to display a hierarchical data to enable select landmark detail ( Province > City > Sub City > District > Metro Station ) , I used taxonomy module ( with some database addition ) to store this hierarchical database structure.
Now on the form, I have a select fields for all those fields linked together with Active Select . My requirement was I need to display the landmark field where as it's value should be the id of the term. So I did the following on my callback function :

function venues_getLandmark($source='', $targets='', $string='', $extra = NULL)
	{
		  if (empty($source) || empty($targets) || empty($string)) {
		    exit();
		  }
		  
		  $targets = explode(',', $targets);
		  $output = array();
		  
		  //var_dump($string);
		  $array = activeselect_explode_values($string);
		  
		  foreach ($targets as $target) {
		    $options = array();
		    
		    $first_element = TRUE;
		    foreach ($array as $key => $value) {
		     
	$vocabulary = db_query("SELECT term_data.name, term_data.tid FROM {term_data},{term_hierarchy} WHERE term_data.tid=term_hierarchy.tid and term_hierarchy.parent=".$key." ORDER BY name");
	while ($term = db_fetch_object($vocabulary)) {
		      $options[$term->tid]['value'] = $term->name;
		      }
		    }
		    $multiple = FALSE;
		    $output[$target] = array('options' => $options, 'multiple' => $multiple);
		  }
		  activeselect_set_header_nocache();		  
		  print drupal_to_js($output);
		  exit();
	}

Now, After making the choice when I submit form , I get the error - " An illegal choice has been detected. Please contact the site administrator. " on all of those fields .

Can you please assists me.
Best Regards
Kaushal

Comments

exodusx’s picture

In activeselect definition add '#DANGEROUS_SKIP_CHECK'=>true, to array
example:
$form['example'] = array(
'#type' => 'activeselect',
'#options' => $options,
'#title' => t('Example'),
'#DANGEROUS_SKIP_CHECK'=>true
);

chop’s picture

Warning:


You should only use the #DANGEROUS_SKIP_CHECK Form API property if you're particularly evil. For more information on this, the most evil of Form API properties, see #DANGEROUS_SKIP_CHECK: the most evil of the Form API properties | groups.drupal.org.
nightlife2008’s picture

Hi people,

After upgrading to D6.13, I've been dealing with the same error on some client's websites. I've been able so solve it and wrote my solution down at: http://www.halecommunications.be/blog/?p=88

Hope I can be of any assistance! Please note that this solution has only been tested on Drupal 6 platforms...

greets,

Kim

DropInTheOcean’s picture

Hi, I have a Drupal 7.2 site, with the 'Profile 2' module. This message ("An illegal choice has been detected. Please contact the site administrator") appears when the visitor does not fill out a radio button (rather than a message saying 'Radio Field required'. Thus the visitors are writing emails to say that they cannot register (because they do not understand the message). I am unsure how to solve this without altering into the code.

[Also unsure of whether to Edit 'issue settings' of this post, or re-post in Drupal 7 forum?]

rogical’s picture

same issue, urgently!

hablutzel1’s picture

Project: Active Select » Drupal core
Version: 5.x-1.x-dev » 7.x-dev
Component: Code » ajax system

Same problem here, please someone explane why does that message appear, I'm getting it with an ajax select input

nod_’s picture

Category: bug » support

This doesn't look like it has anything to do in core.

pasqualle’s picture

Status: Active » Closed (fixed)

The message appears because the submitted value is not part of the original select list. Typical problem with dynamically created select list options.
The https://drupal.org/project/examples module has some good examples how to modify form elements dynamically.

sinasalek’s picture

Status: Closed (fixed) » Active

When #ajax is used for a select element, if more than one options is selected "illegal choice error" will be generated. But why?
After a bit of investigation it turned out that when #ajax is enabled it causes the select element to submit values like array(200,250) instead of array(200 => 200, 250 => 250)
So it causes problem with options validation code inside _form_validate function and it no longer can check selected options against available options, here is the code :
This happens only when more than one option is selected and #ajax is used. The fix is to correct the submitted value before validation

        if (is_array($elements['#value'])) {
          $value = in_array($elements['#type'], array('checkboxes', 'tableselect')) ? array_keys($elements['#value']) : $elements['#value'];
          foreach ($value as $v) {
            if (!isset($options[$v])) {
              form_error($elements, $t('An illegal choice has been detected. Please contact the site administrator.'));
              watchdog('form', 'Illegal choice %choice in !name element.', array('%choice' => $v, '!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
            }
          }
        }
sinasalek’s picture

Category: Support request » Bug report

There seems to be no way to workaround this via a module. _format_validate is call very early in form validation :(

sinasalek’s picture

A workaround has been found using #after_build but it's ugly :)
It's possible to correct the submitted values using a custom after_build callback and before _form_validation is called

sinasalek’s picture

pasqualle’s picture

Title: An illegal choice has been detected. Please contact the site administrator. » Wrong submit values for multiple select under ajax submit
john morahan’s picture

Updating the jQuery form plugin (#2266303: Update jquery.form.js) also seems to fix it, at least for me.

jordanmagnuson’s picture

Confirming that updating jquery.form.js to 3.51 as per #14 solved this issue for me.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.