[html-formfu] Constraining filenames for upload fields

Will Hawes wdhawes at gmail.com
Wed Jul 30 18:05:24 BST 2008


I'd like to add a constraint to a form to limit the file suffix a user
is allowed to enter into an upload field. This is not to check file
type (that's done elsewhere in my code), rather it is intended to make
the form slightly more user friendly by trying to catch
invalid-looking file names early on.

I've got something like

elements:
  - type: File
    constraints:
      - Required
      - type: Regex
        regex: \.(gif|jpe?g|png)$
        message: Submitted filename looks invalid.

But the regex is never matched - the Regex constraint tries to match
against a HTML::FormFu::QueryType::Catalyst object rather than a
scalar value for fields of type "File".

I think patching that class to stringify to the contents of e.g. its
"filename" field, or possibly adding a "field" method to the Regex
constraint to indicate which field to match against, might be useful.

Or maybe there are better ways to do this?



More information about the HTML-FormFu mailing list