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
Comment #1
exodusx commentedIn activeselect definition add '#DANGEROUS_SKIP_CHECK'=>true, to array
example:
$form['example'] = array(
'#type' => 'activeselect',
'#options' => $options,
'#title' => t('Example'),
'#DANGEROUS_SKIP_CHECK'=>true
);
Comment #2
chop commentedWarning:
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.
Comment #3
nightlife2008 commentedHi 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
Comment #4
DropInTheOcean commentedHi, 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?]
Comment #5
rogical commentedsame issue, urgently!
Comment #6
hablutzel1 commentedSame problem here, please someone explane why does that message appear, I'm getting it with an ajax select input
Comment #7
nod_This doesn't look like it has anything to do in core.
Comment #8
pasqualleThe 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.
Comment #9
sinasalek commentedWhen #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
Comment #10
sinasalek commentedThere seems to be no way to workaround this via a module. _format_validate is call very early in form validation :(
Comment #11
sinasalek commentedA 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
Comment #12
sinasalek commentedI wrote a module for this https://www.drupal.org/sandbox/sinasalek/2312751
Comment #13
pasqualleComment #14
john morahan commentedUpdating the jQuery form plugin (#2266303: Update jquery.form.js) also seems to fix it, at least for me.
Comment #15
jordanmagnuson commentedConfirming that updating jquery.form.js to 3.51 as per #14 solved this issue for me.