Validation on File Field

We have a required sys_File control field that won’t run any validation on the field. I have tried a few different ways to validate the field and it never returns back an error. Is there something I am missing on validating file fields, or is validation turned off for these fields?

You could check that the file size field is greater than zero. That’s how we have set up our image content type (although the use of shared fields means we constantly have to fix it after MSM’ing from our development server to our production server.)

If you have the sys_FileInfo extension set up in the content type’s Pre-Processing tab, it should populate a field (which you have to set up) called foo_size (if foo is the name of the sys_File field.)

There may be better approaches. With this method, if some other validation rule is broken, the sys_file is cleared and the user has to click Browse and find the file he wants to upload again.

Andrew.

The first thing to realize is that Rx will create a temp file even when no file is submitted, so you can’t just check the ‘Required’ checkbox. Also, since binary fields are not submitted every time, you have to do special handling, otherwise, you would not be able to update the item w/o resubmitting the file.

First, the ‘Clear’ checkbox should be disabled, as you never want the field to be empty.
2nd, add a pre-condition that will cause the validation to only fire when the item is inserted: single html param sys_contentid IS NULL.
The actual validation needs 2 conditions: single html param fieldname IS NOT NULL and single html param fieldname > 0.

This should accomplish what you want.

This worked great. Thank you.