Once I have an attachment on a node, the only attachment checkbox options I'm allowed to have to submit the form is "List" or "List and Delete".

Expected behavior:
Delete alone should be able to delete the attachment, and nothing checked should keep the file, list it when you edit it, and not display the link to the public.

Error message:
Illegal choice in .

Comments

chx’s picture

Assigned: Unassigned » chx

Now you wait, you tell me that form choices patch broke upload? Damn!

m3avrck’s picture

This also caused problems with project module too, getting illegal choice a lot as well.

m3avrck’s picture

I think this might be related to this issue: http://drupal.org/node/42008

matt westgate’s picture

Title: attachment checkboxes too restrictive » attachment checkboxes throwing "Illegal choice in ." error
Status: Active » Needs review
StatusFileSize
new1.02 KB

How to Reproduce

Upload a file to a node and hit submit. Then edit the node again and uncheck the 'list' option. The form will not validate and throw an "Illegal choice in ." error. In otherwards you currently have to list the files because the error prevents anything else.

The Problem

Line 153 in _form_validate() expects the keys of the $elements['#value'] array to be the index of the file number to validate (i.e., validate the first file, second file, etc). Currently the values (not the keys) in $elements['#value'] contains the information _form_validate() is looking for.

The Fix (I hope)

$elements['#value'] is being populated in _upload_form(), so we just need to swap around the values there.

hunmonk’s picture

pretty sure this isn't the problem. it's a bit convoluted, but if you look here in form.inc:

    if (!isset($form['#value'])) {
      if ($posted) {
        if (isset($edit)) {
          $form['#value'] = $edit; // normal element
        }
        elseif (isset($form['#return_value'])) {
          $form['#value'] = 0; // checkbox unchecked
        }
      }
      if (!isset($form['#value'])) {
        $form['#value'] = $form['#default_value'];
      }
    }

i *think* what's happening is that for the checkboxes form element itself (prior to expansion), there is no 'return_value', but there can be a 'default_value'. this seems to be causing $form['#value'] to be set to an incorrect array for the checkboxes form element in the particular case where all checkboxes are unchecked.

can anyone else confirm this logic?

matt westgate’s picture

StatusFileSize
new3.1 KB

Here's an updated patch which also resolves some of the larger checkbox issues hunmonk is referring to. Although there may be bigger patch coming which cleans up checkbox logic even more.

m3avrck’s picture

Status: Needs review » Closed (duplicate)

As instructed by chx this is a duplicate of: http://drupal.org/node/39179