Required flag on file forms breaks on validation

Bèr Kessels - April 21, 2006 - 13:43
Project:Drupal
Version:7.x-dev
Component:file system
Category:bug report
Priority:normal
Assigned:quicksketch
Status:needs work
Issue tags:D7FileAPIWishlist, ImageInCore
Description

A file form, that is required will always fail. Since there is no #value set (theoratically, there is no value at all) the validation will start nagging about the field having no value.

We either need a different validation for requirement of files in form api, or we need to set something usefull (like the $file object) as #value, once file.inc validated the file.

Flexinode file fields are one of the cases where this behaviour can be reproduced.

#1

samc - April 24, 2006 - 03:13

Backlink to open flexinode issue: http://drupal.org/node/42762

#2

adrian - April 24, 2006 - 14:13
Assigned to:Anonymous» vertice@www.drop.org

#3

chx - April 24, 2006 - 19:53
Status:active» reviewed & tested by the community

(21:46:24) vertice:  the problem is that during the upload process, the stuff gets removed OUT of the form system
(21:46:28) vertice:  and gets stuffed in the session
(21:46:36) vertice:  and every file api module does this on it's own

This is not the place neither the time to fix file API. Everybody on its own. I am outta here. If the change gets in, I will doc the change.

AttachmentSizeStatusTest resultOperations
no_file_req.patch739 bytesIgnoredNoneNone

#4

killes@www.drop.org - April 25, 2006 - 10:20

I am not too happy about it, but unless somethign better comes up, I will commit it.

#5

Bèr Kessels - April 25, 2006 - 10:27

This works. It fixes the issue.

but:
* Its a HACK, spelled in capitals all along. Whether or not we allow such a hack to get in to solve this issue, or not, is not up to me.
* Will it not open up a bit of a security hole? I mean: if we are making exceptions that will allow certain "things" not to pass by the validation, we are moving on slippery ice (or whatever the saying is).

but:
again: it solves the issue. Tested, and confirmed with a few flexinode file fields.

thanks. but I dare not give it a + or - 1. Such issues, IMO are for Dries to decide.....

#6

Bèr Kessels - April 25, 2006 - 10:31

I forgot to mention, that there are other ways around this issue. For example image.module does this. They are not solutions, but simply ways to not run into this form api bug.

* do not set the required flag on a file field.
* then validate it yourself in a validation hook.

The downside is, that the "required" mark (by default the *) is not printed on the file form.

#7

killes@www.drop.org - April 25, 2006 - 10:44

Maybe we should simply document that you can't use required with file fields. Also, Ber coul dpass an attribute to his home-brew validation routine.

Since this issue does not affect core, I'd like to not patch core, but to simply update the docs. Opinions?

#8

samc - April 25, 2006 - 13:34

Like the previous posters, I'm not crazy about the idea of introducing such a hack into core.

I may have found a potential workaround, at least as far as flexinode goes (but should be generally applicable).

Can you guys take a look at http://drupal.org/node/42762, #12. It seems to work fine... Am I missing something that makes this a bad approach?

It might be better to ensure that that type of approach is supported via forms system, rather than just bypass required checking for file fields.

What do you think?

#9

moshe weitzman - April 25, 2006 - 14:26

I'm OK with this patch for 4.7.0. We can make it work properly for 4.7.1 IMO

#10

chx - April 25, 2006 - 18:50
Status:reviewed & tested by the community» won't fix

We agreed that the solution is that I am doccing right now that #type file can't be required.

#11

Bèr Kessels - April 26, 2006 - 11:39
Priority:critical» normal
Status:won't fix» active

I am sure we agreed to lower the priority and move this to the "file system" component. "wont fixes" will be forgotton. This should not be forgotton.

For it remains a bug.

#12

nedjo - July 30, 2006 - 17:39

I marked http://drupal.org/node/64984 as a duplicate. There is a patch on that issue.

#13

Bèr Kessels - August 1, 2006 - 07:11

Attached the patch by quicksketch on #64984

AttachmentSizeStatusTest resultOperations
form-inc-require-file-field_0.patch923 bytesIgnoredNoneNone

#14

neclimdul - September 11, 2006 - 23:20

Patch does not apply and a conversion of the patch does not seem to work.

#15

bomarmonk - January 26, 2007 - 08:31
Version:x.y.z» 4.7.5

Is a patch applied for 4.7? It seems that is should be, as flexinode is still better at handling files and many sites are using it. This seems like a sad oversight... apply a patch to core that fixes this, please (easy for me to say, since I'm more of a bug hunter than a bug fixer). Just throwing my support at this as loudly as possible.

#16

webchick - April 19, 2007 - 20:53
Version:4.7.5» 6.x-dev
Status:active» needs work

This is still an issue in 5.x and, presumably, HEAD.

This prevents programmatically creating node content with drupal_execute on imagefields, for example, when the field's #required property is set to TRUE.

#17

ilmaestro - October 29, 2007 - 17:30

...still an issue.

I'm sure it goes without saying, but stating that the #required setting is not allowable for file types is a pretty lousy solution.

#18

jakeg - February 18, 2008 - 14:49

it may be a lousy option to say #required is not allowable for file types, but at the moment #required doesn't work for them and I've just spent hours trying to figure out where in my script I was going wrong not getting it working. I had already done my own workaround (also suggested above) of having my own #validate function and doing stuff in there, and not having the field #required, but the fact that the docs say #required is allowed is very confusing. For now at least, the docs must be changed to make #required not an option for 'file' form fields, otherwise other coders will face the same headache in figuring out where they've gone wrong in implementing it.

#19

webchick - February 18, 2008 - 15:46

@jakeg: Please update the docs. Anyone with a CVS account may do so. The file's in contributions/docs/developer/forms_api_reference.html, I believe.

#20

jakeg - February 18, 2008 - 21:49

@webchick: thanks, I didn't realise/think I had access. Have updated the docs:
http://cvs.drupal.org/viewvc.py/drupal/contributions/docs/developer/topi...

#21

celstonbg - June 11, 2008 - 13:57

Subscribing

Patch from post #13 appears to be working in my 5.7 instance.

#22

quicksketch - July 12, 2009 - 07:30
Version:6.x-dev» 7.x-dev
Assigned to:vertice@www.drop.org» quicksketch

Ha, this was "fixed" 3 years(!) ago in #64984-4: File Uploads fail when field is set to "required", but it never made it into core. Sad, sad. Here's a reroll of my old patch, not yet tested, but just putting this on the radar.

AttachmentSizeStatusTest resultOperations
file_required.patch1.1 KBIdlePassed: 14717 passes, 0 fails, 0 exceptionsView details | Re-test

#23

quicksketch - July 12, 2009 - 07:42
Status:needs work» needs review

Updated patch that has been tested.

AttachmentSizeStatusTest resultOperations
file_required.patch1.11 KBIdlePassed: 14695 passes, 0 fails, 0 exceptionsView details | Re-test

#24

unknownguy - July 12, 2009 - 18:37

@jakeg: thanks for fixing up the documentation, it was really important IMHO and I have experienced this headache so I totally agree with #18

#25

drewish - July 12, 2009 - 23:22

subscribing

#26

drewish - July 12, 2009 - 23:24

seems like we could use a unit test for this...

#27

moshe weitzman - July 13, 2009 - 02:02
Status:needs review» reviewed & tested by the community

Fixes a bug that has pestered since FAPI 1.0. A test would be nice but squashing the bug is more important.

#28

drewish - July 13, 2009 - 06:10

i'd disagree since the whole point of the test is making sure it says unbroken.

#29

webchick - August 3, 2009 - 21:50
Status:reviewed & tested by the community» needs work
Issue tags:+Needs tests

Wow!! Great to see this bug fixed! But I agree that a test is mandatory.

Also, is there by chance a nicer way to get this value than $elements['#parents'][0]? that's not really at all intuitive.

#30

sreynen - August 31, 2009 - 18:28
Status:needs work» needs review
Issue tags:-Needs tests

On testing, the previous patch went too far and didn't throw an error when a required file field was actually missing a file. Updated patch, including a test.

AttachmentSizeStatusTest resultOperations
file_required.patch3.33 KBIdleFailed: Failed to apply patch.View details | Re-test

#31

System Message - September 18, 2009 - 09:05
Status:needs review» needs work

The last submitted patch failed testing.

#32

sreynen - September 19, 2009 - 15:07
Status:needs work» needs review

#33

System Message - September 19, 2009 - 15:20
Status:needs review» needs work

The last submitted patch failed testing.

#34

moshe weitzman - September 19, 2009 - 17:51

@Scott - the bot tested today and this patch will not apply cleanly :(

#35

sreynen - September 21, 2009 - 04:35
Status:needs work» needs review

Updated patch for most recent 7.x-dev release.

AttachmentSizeStatusTest resultOperations
file_required.patch3.45 KBIdleFailed: Failed to apply patch.View details | Re-test

#36

System Message - November 9, 2009 - 08:55
Status:needs review» needs work

The last submitted patch failed testing.

 
 

Drupal is a registered trademark of Dries Buytaert.