Download & Extend

#default_value not working for file field type

Project:Drupal core
Version:4.7.2
Component:forms system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (won't fix)

Issue Summary

According to the api docs, #default_value is a supported property of the file form control.

However this isn't working in my testing. Example:

<?php
  $form
[$fieldname] = array(
   
'#type' => 'file',
   
'#title' => t($field->label),
   
'#description' => ($node->$fieldname ? t('"%filename" has been uploaded. If you upload another file, the current file will be replaced.', array('%filename' => $node->$fieldname->filename)) : '') . t($field->description),
   
'#required' => $field->required,
   
'#weight' => $field->weight,
   
'#default_value' => 'TESTING.txt',
    );
?>

Comments

#1

I agree, its not working here either

#2

turns out it is not supported on most browsers due to security issues

(ie: you could set the default value to be c:\somesecretfile, hide the file field in a no-display div and then just show the submit button...)

#3

Version:4.6.6» 4.7.2
Status:active» closed (won't fix)

Yeah. See Input File Value thread on Evolt.org for further details.

The value type in file input fields is not supported by any browser that I know of for these reasons. Doesn't make sense for Drupal to support it either. Setting to won't fix.

nobody click here