Uploaded files with required file fields not detected during validation

haykelbj - July 29, 2006 - 15:20
Project:Drupal
Version:4.7.6
Component:forms system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:won't fix
Description

When a form contains a file filed that is marked as required, the _form_validate() function always rises the error 'field is required' even if the field was not empty. I found that the value of $elements['#value'] for file fields is always empty during form validation in _form_validate(). If this is normal behavior, than a special test for file fields is needed. One solution could be to replace:

<?php
if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0')
?>

with
<?php
if ($elements['#required'] && (($elements['#type'] == 'file' && !file_check_upload($elements['#title']) || ($elements['#type'] != 'file' && empty($elements['#value']) && $elements['#value'] !== '0'))))
?>

But if the element should anyway have value, than the error is somewhere else.

#1

magico - September 21, 2006 - 05:07

In these cases could be provided a small test case for us: testers!
@haykelbj: could you chek if this still applies to HEAD? Thanks.

#2

magico - January 15, 2007 - 19:45
Version:4.7.2» 5.x-dev

The code still exists as stated. Must take another look next time, to confirm this problem.

#3

haykelbj - February 21, 2007 - 10:15

sorry, I'm not using drupal anymore but as I remember it should be easy to reproduce the problem: just create a form with a file field and mark it as required. Then use the form, fill the file field with a valid path and submit the form, you should still get the error 'field is required'. Good luck!

#4

cyvan - March 26, 2007 - 12:35
Version:5.x-dev» 4.7.6

I can confirm this still being a problem in 4.7.6 .
If you create a form with a file field set as required, the file upload is not being recognized.
The required setting being switched off makes the form behave as expected.

#5

Pasqualle - September 15, 2008 - 22:21
Status:active» won't fix

This version is not supported. Reopen or create a new issue if the problem exists in any recent version (version equal or above Drupal 5)

#6

kees@qrios - April 20, 2009 - 15:23
 
 

Drupal is a registered trademark of Dries Buytaert.