Problem/Motivation

  • AJAX form submissions seem to fail validation for other fields in the form. Examples:
    • uploading files to filefields
    • adding values to multiple-value fields

Sample steps to reproduce

  1. Create a new content type with a List (text) field, check/box radio button widget, allowed values Y and N, and make it required.
  2. Leave default value empty.
  3. Add a Filefield, allow these extensions: doc, docx, pdf, xls, xlsx, txt, and leave all other settings set to default (not required, public files, etc.).
  4. Allow these extensions: doc, docx, pdf, xls, xlsx, txt..
  5. Create content of the new type.
  6. Leave the List (text) field blank
  7. Upload an XLS file to the Filefield

Result:

Proposed resolution

  • TBD

Remaining tasks

  • TBD

User interface changes

  • TBD

API changes

  • TBD

Original report by gipsyx

All my file fields get an error when I try uploading files. I tried it on different content types, with different allowed extensions.

The error log says it's a form error, the message "Illegal choice in Type element."

The file fields where working fine until today, the only difference I could imagine was that I did some automatic updates, but I can't find a log of updated modules.

I don't know exactly what informations you need to fix this, please let me know if you need to know something else.

CommentFileSizeAuthor
#9 Screenshot.png37.04 KBpeezy
Capture d’écran 2011-05-19 à 18.05.16.png43.34 KBAnonymous (not verified)

Comments

roam2345’s picture

Can we see the file field settings you used?

Anonymous’s picture

This is the file field export from Features. Does that help?

// Exported field: 'node-teaser_big-field_teaser_swf2'
  $fields['node-teaser_big-field_teaser_swf2'] = array(
    'field_config' => array(
      'active' => '1',
      'cardinality' => '1',
      'deleted' => '0',
      'entity_types' => array(),
      'field_name' => 'field_teaser_swf2',
      'foreign keys' => array(
        'fid' => array(
          'columns' => array(
            'fid' => 'fid',
          ),
          'table' => 'file_managed',
        ),
      ),
      'global_block_settings' => '1',
      'indexes' => array(
        'fid' => array(
          0 => 'fid',
        ),
      ),
      'module' => 'file',
      'settings' => array(
        'display_default' => 0,
        'display_field' => 0,
        'uri_scheme' => 'public',
      ),
      'translatable' => '1',
      'type' => 'file',
    ),
    'field_instance' => array(
      'bundle' => 'teaser_big',
      'deleted' => '0',
      'description' => '',
      'display' => array(
        'cck_blocks' => array(
          'label' => 'above',
          'settings' => array(),
          'type' => 'hidden',
          'weight' => 0,
        ),
        'default' => array(
          'label' => 'above',
          'module' => 'file',
          'settings' => array(),
          'type' => 'file_default',
          'weight' => 5,
        ),
        'teaser' => array(
          'label' => 'above',
          'settings' => array(),
          'type' => 'hidden',
          'weight' => 0,
        ),
      ),
      'entity_type' => 'node',
      'field_name' => 'field_teaser_swf2',
      'label' => 'Swf File',
      'required' => 0,
      'settings' => array(
        'description_field' => 0,
        'file_directory' => '',
        'file_extensions' => 'txt swf',
        'max_filesize' => '',
        'user_register_form' => FALSE,
      ),
      'widget' => array(
        'active' => 1,
        'module' => 'file',
        'settings' => array(
          'insert' => 0,
          'insert_class' => '',
          'insert_default' => 'auto',
          'insert_styles' => array(
            'auto' => 'auto',
            'image' => 0,
            'image_full_width' => 0,
            'image_half_width' => 0,
            'image_large' => 0,
            'image_medium' => 0,
            'image_newsletter_preview' => 0,
            'image_thumbnail' => 0,
            'image_tiny' => 0,
            'image_watch_detail' => 0,
            'image_watch_detail_thumbnail' => 0,
            'image_watch_overview_small' => 0,
            'link' => 0,
          ),
          'insert_width' => '',
          'progress_indicator' => 'throbber',
        ),
        'type' => 'file_generic',
        'weight' => '7',
      ),
    ),
  );
sun’s picture

Component: forms system » file.module
Category: bug » support
Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)

If this is really a bug in core, then we need clear steps to reproduce this bug in core (without contrib modules).

Wappie08’s picture

Component: file.module » forms system
Category: support » bug
Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Active

Hello Sun, I just reproduced this error, hopefully this is reproducable on a clean install (mine was not clean).

The bug is quite nifty:

- set a integer list field with some keys + values and set the field to required. Then either set the default value to N/A or do not touch the field at all.
- Then put an imagefield of filefield in the form and it gives an error when trying to upload an image/file before selecting an option on the required integer list.




I also had some form_alter functions which produced errors when uploading files, I figured out that putting all form_alter functions inside a if ($form_state['executed'] == FALSE) {} prevented all errors.

Greetings Wappie

dawehner’s picture

I tryed to reproduce the issue by

  • adding a list-integer field with 0|a,1|b... with default to none
  • adding an image field

Then creating a node of this new type, touching nothing and upload a single image without changing the list-integer field.
And it worked fine without any kind of validation errors. The version used is the current git checkout of 7.x

xjm’s picture

Version: 7.0 » 7.x-dev
Status: Active » Closed (cannot reproduce)

I was also unable to reproduce this bug using a current checkout of core and following exactly the steps provided in #4. It may already have been resolved by another issue if it was indeed a bug in 7.0. Otherwise, it may be related to contrib or custom code. Reopen if you can reproduce using 7.x-dev or 8.x-dev, and post exact steps to reproduce starting from installation. If the error only occurs after an upgrade from 6.x, then we'll want steps to reproduce from the D6 install if at all possible.

peezy’s picture

Status: Closed (cannot reproduce) » Active

I was able to reproduced the illegal choice error on 7.10-dev and 7-9 by doing this:

  1. Create a new content type with a List (text) field, check/box radio button widget, allowed values Y and N, and make it required.
  2. Leave default value empty.
  3. Add a Filefield, allow these extensions: doc, docx, pdf, xls, xlsx, txt, and leave all other settings set to default (not required, public files, etc.).
  4. Allow these extensions: doc, docx, pdf, xls, xlsx, txt..
  5. Create content of the new type.
  6. Leave the List (text) field blank
  7. Upload an XLS file to the Filefield

The log reports the illegal choice in the List field.

xjm’s picture

#7 doesn't sound to me to be related to the filefield? You're making the list field required and then submitting no value.

peezy’s picture

StatusFileSize
new37.04 KB

Thanks for replying so quickly! I'll gladly post this elsewhere, if you wish.

So that you know, the error occurs only when I upload a file and only with the Radio Buttons/Checkbox widget (so, I'm not actually saving the node). When I change the text to a select list, I get the expected behavior (no error on upload). Also, the error renders in the Filefield area and not at the top of the page (please see attached screenshot).

xjm’s picture

Ahh. So it sounds like the AJAX submission is doing validation on the rest of the form, perhaps?

xjm’s picture

Title: Unable to upload files with File Field. Error "An illegal choice has been detected. Please contact the site administrator." » AJAX callbacks try to validate other form fields: "An illegal choice has been detected."
Version: 7.x-dev » 8.x-dev
xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Title: AJAX callbacks try to validate other form fields: "An illegal choice has been detected." » AJAX submissions try to validate other form fields: "An illegal choice has been detected."
xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

See also #811542: Regression: Required radios throw illegal choice error when none selected, which we should take into consideration when testing this.

Anonymous’s picture

Status: Active » Closed (duplicate)

yep, with the latest patch at #811542: Regression: Required radios throw illegal choice error when none selected i can't reproduce this any more. marking this as duplicate.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

elijah lynn’s picture