Two days ago I upgraded from 7.28 to 7.29 and now my website has serious problems. Managed file form elements no longer submits it's default values. For example, this form worked perfectly and now does not:

    $form['function'][$item->idFunction] = array(
      'name' => array(
        '#title' => t('Function name'),
        '#title_display' => 'invisible',
        '#type' => 'textfield',
        '#size' => 30,
        '#maxlength' => 120,
        '#default_value' => $item->FunctionNameInner,
      ),
      'FunctionIcon' => array(
        '#type' => 'managed_file',
        '#title' => t("Function's function"),
        '#title_display' => 'invisible',
        '#upload_validators' => array(
          'file_validate_extensions' => array('gif png jpg jpeg'),
          'file_validate_size' => array(variable_get('mymodule_image_size', 5 * 1024 * 1024)),
        ),
        '#upload_location' => 'public://mymodule/function',
        '#default_value' => $item->FunctionIcon,
        '#required' => TRUE,
        '#theme' => 'preview_upload',
      ),
      
      'Important' => array(
        '#type' => 'checkbox',
        '#title' => t('Important'),
        '#title_display' => 'invisible',
        '#default_value' => $item->Important,
      ),

      'id' => array(
        '#type' => 'hidden',
        '#default_value' => $item->idFunction,
      ),
      
      'weight' => array(
        '#type' => 'weight',
        '#default_value' => isset($item->weight)?$item->weight:'',
        '#delta' => 100,
      ),
    );

When I submit this form without changing anything, default file IDs are in $_POST as expected, but they are no longer in $form_state['values']

Comments

aquasoftwares’s picture

I have same problem with my theme settings form. It was working before upgrade. When i downgraded drupal version back to 7.28 it started working.

dcam’s picture

Please check #2305017: Regression: Files or images attached to certain core and non-core entities are lost when the entity is edited and saved and see if this could be a related issue. You might try applying the patch from that issue and see if it solves the problem.

David_Rothstein’s picture

'#default_value' => $item->FunctionIcon,

What's the story with the file represented by this variable; where else in Drupal is it attached to?

I tried the above code and could only reproduce the problem if the only place it's attached to is one of the "problem" entity types (for example, taxonomy terms) mentioned in #2305017: Regression: Files or images attached to certain core and non-core entities are lost when the entity is edited and saved... if it's attached to a node it all works OK. (And in my testing it had to be referenced by something, or the managed_file validation won't let it through at all; that's the case in Drupal 7.28 and earlier too.)

In any case, the patch in the above issue also fixed the problem when I tested it, so I'm hoping that's the case for the real example too?

I'll add something to the known issues section of the 7.29 release notes to indicate that custom managed_file form elements can be affected as well.

Mołot’s picture

dcam is right. How do I close this issue as duplicate? Or delete it?

dcam’s picture

Status: Active » Closed (duplicate)

The status just needs to be changed. Thank you for replying back to let us know.