I get the vague "An illegal choice has been detected. Please contact the site administrator." error when I try to upload an image in an image field of one of my content types.

The content type also has several check boxes/radial buttons fields. I only get the error if the check box fields don't have a selection made. If I give all th check box/radial button fields a default value and leave them as such, or otherwise make sure they all have a selected value, I do not get this error.

I'm not sure this is even a core issue, but if anyone knows what the problem is, or how to correct it, I would really appreciate the help.

Comments

baby.hack’s picture

On further examination, it seems to be one of the radial button fields. That field had "number of values" allowed set to 1, was a required field, and used a taxonomy vocabulary.

Deleting that one field allowed upload of image field data without the error.

One of my other radial button fields also had a 'number of values' allowed set to 1, but was not a required filed, and was not a taxonomy vocab. Changing this field to required reproduced the error. Changing the "number of values" allowed to 2 removed the error.

So it seems that a radial button field with a "number of values" set to 1 and the field set as required causes, for me at least, a "An illegal choice has been detected. Please contact the site administrator." error when trying to upload an image in an image field. Note that the upload is taking place durring node creation, not during node save.

Also, when the error does occur, I'm prevented from uploading further images in that field, but, I can complete the node creation form, save the node, then go back to edit it, and the uploaded image is still there, and I can now upload other images.

While not on a clean install, I was able able to reproduce this error in a new content type made for the purpose. I get this error on both my production server and my development server.

etavener’s picture

Hi did you manage to solve this issue? I've got the same problem and it is really holding me back.

baby.hack’s picture

@etavener
I'm not very familliar with what's under the hood in Drupal, but I have my theories. I think that somehow the whole node form is checked when an image is uploaded.

The radio button taxonomy term field that I have is required. At the time the image is uploaded, that radio button field has no value, and the form throws an error.

My sollution was to provide a default value for any taxonomy term field that fits this case (is required and number of values limited to 1).

Of course, this means that the node creator isn't given a warning when they don't pick a value for those taxonomy term fields, as a default value is provided. Custom node validation might be needed if you want to be sure that the creator is choosing a value other than default.

I've added node validation via a custom module, but Rules Forms (http://drupal.org/project/rules_forms) might help out with that, though it is still in beta.

It's a bit of a messy fix, but it works for me.
As per W3C standards, radios should always have a default, anyway: http://drupal.org/node/621366

tanitani’s picture

@baby.hack
Thank you very much for your clear issue description and that you came back to report your further findings.
I just came across this issue on the site I am building for a client. What is weird is that this issue did not seem to appear for a while. (I had an editor adding and modifying content and he didn't report any problems. I should recreate that set up to see if the issue was there, though Drupal's structure is so vast I am not sure what I would compare...
Recently I have been mucking around with the workbench module, which I can't seem to get to work (no save button when Moderation is enabled), so I am not sure... If I figure out something, I will come back to report.

Gábor

cigotete’s picture

I found other solution. if you only need one option, then change the widget to "select list". with select list the message will not appear.

phponwebsites’s picture

Hi i have used "Select list" widget for taxonomy term. But i'm also getting this error while uploading image.

ASMBL’s picture

Thanks for the solutions. I can report that I am also running into this problem. From reading the error message I had stumbled upon providing a default value, however unsuitable. Speaking to the W3C comment above about radios always requiring default selections, I found that if I designated (the Drupal built-in non-displaying value) N/A as the default selection for the radio selection, it never stuck. To me, this meant that, although a value was selected, it was not making it through the save process and was not reflected in the database. Immediately reloading the add content and uploading and removing images would result in the same errors.

Ultimately, the drop menu solution is what I went for. Thanks again.

alexborsody’s picture

Was having this same problem, my solution was to give a default value to the required field (radio button). From the content type edit page. This of course does remove that extra step of validation if someone forgets to set that radio button to the correct value for the node they are creating, but it seemed like the fastest and simplest fix.

sstacks’s picture

I can confirm this also fixed my problem.

Setting a default value for radio selections on forms with image uploads prevents the error message,

Dhammika’s picture

I can confirm the workaround did not work for me

alexborsody’s picture

see if there are any other form values on the page, that may need defaults selected.

Gastonia’s picture

I am having the same issue and can confirm that selecting a default value for my taxonomy radio buttons did not fix the issue. However, I removed the taxonomy field and everything started working again.

This seems to be an issue that occurs when a taxonomy field is enabled on the content type and set to 'required' as well as when using the 'radio / checkbox' widget.

This seems like a Drupal bug? Would it be possible to move this thread into issues for core?

Anyone found a confirmed cause / solution for this? I am running 7.12. All modules are up to date.

Thanks!

lomo’s picture

This seems like a Drupal bug? Would it be possible to move this thread into issues for core?

This is a forum topic. There is currently no way to promote/convert a forum topic into a bug report (project issue), but you could link to this topic in a bug report that you file or if you post a comment on an existing (i.e. "likely related") project issue.

See you at the Drupalcon!

phponwebsites’s picture

Hi i have also same probllem. I have added image upload field using media browser and taxonomy dropdown field. When i trying to upload image using media browser, i am getting "An illegal choice has been detected. Please contact the site administrator." error.

I tried to set default value for dropdown list and check again. But still i'm getting same error. Any sollutions?

Note: I got this error only when the image field is required. If the image field is not required, then i didn't get this error.

vishal.sirsodiya’s picture

Hi, I am facing same issue. when I am uploading image in node edit, that time my select list options are reset. and my observation is that, that time $form_state value is not set for that select box.

Please suggest me, how we handle that condition.

bribread22’s picture

I was also getting this same vague message and just found the solution to it. The issue with me is that I was using the Form API and I had two form elements with the same key ('tbl') being brought in from two different functions. Using a different table key solved the issue for me. See below:

function my_form($form, &$form_state) {
  // Please disregard where I am getting the $header and
  // $options variables. I am just using this as an example.
 
  $form['tbl'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No users available.'),
  );

  $form['tbl'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No users available.'),
  );

  return $form;
}