Webform select field validation throws: An illegal choice has been detected. Please contact the site administrator.
| Project: | Webform |
| Version: | 6.x-2.7 |
| Component: | Code |
| Category: | support request |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
| Issue tags: | form validation, select, webform |
Jump to:
Hi gurus,
Recently, i have updgaded one corporate site to Drupal 6.12 and all of its custom modules, including webform.
The old version of a webform was 6.x 2.1.3 and now its 6.x 2.7.
I have a form with select boxes, that initially do not have any values, and i use jquery and other JS to populate them. These select boxes depend on each other selected values.
So before the update, i could create an empty select field and on form submition all values were saved, but now, all my empty select fields do not pass form validation and throw: An illegal choice has been detected. Please contact the site administrator.
I when try to add new empty select, then it says, i must specify select items...
Does anyone have a solution to this kind of problem?
May be it is possible to specify, if a field needs to be validated if it does not have any option items set?
Please help!!!

#1
What you're trying to do is not possible because it violates Drupal's security measures (as you've noticed). An alternative is to use a textfield instead, then populate the value of that textfield via jQuery and a select list.
#2
boy.. I wish I came across this support request before I did exactly the same thing as warriory2k. I am desperately trying to get the terms in a vocabulary into a select list in my webform and totally thought I found a work around using javascript.
warriory2k.. have you come up with a resolution yet?
qucksketch.. I don't understand what you mean by "An alternative is to use a textfield instead, then populate the value of that textfield via jQuery and a select list." Could you explain further?
I'm at my wits end trying to figure out how to get my vocabulary in a select list and unfortunately I'm between a rock and hard place with my client on this issue. I would appreciate any help on getting this resolved. (sorry if I'm hijacking this thread..)
#3
I had a brainstorm on the way in to work this morning and have since resolved my issue. This is how I did it in case others are looking for inspiration.
Using the markup component I made my own select form element. I populated that element with my database data. The webform module ignores form elements created through the markup component (or at least that has been my experience) so it doesn't throw any errors when the form is submitted.
To be able to actually submit the selected option from that form element I created a hidden form element (using the hidden component) and set it's value to equal the option that was selected in the select element.
This appears to be working just fine, I'm able to create a custom select element with dynamic data, and pass the result through the module so it's recorded and viewable when you go and look at the results.
Hope that helps others who might be suffering through the same issue.
#4
#5
Will you please provide additional detail on how you do this?
#6
A slightly clumsy but safe and workable solution for a select box is to include all the possible options initially by default. The initial value of the previous select box must then be something like "-please select-" to force the user to make a valid selection, so that the cascading select box then displays the relevant options via JQuery. This overcomes the "An illegal choice has been detected" error because the form validation sees all the valid options that were initially loaded.