When there are multiple <input type="file" name="fname"> with the same name, web.input(fname={}) returns only the last one. #33

Closed
anandology opened this Issue Nov 29, 2010 · 2 comments

1 participant

@anandology

Reported on Launchpad by Hudson Lee on 2010-04-11.

https://bugs.launchpad.net/webpy/+bug/560278

 

In webpy .34 release.

When there are multiple <input type="file" name="fname"> with the same name, web.input(fname={}) returns only the last one.

This happens to be how: <input type="file" multiple=""> submits it's files.
(works in ff3.6 & recentish chrome/safari)

My fix for this is in utils.py storify() line 147: change

else:
    value = value[-1]

TO:

elif not isinstance(defaults.get(key), dict):
    value = value[-1]

Related Suggested Change:

I hate having todo: web.input(email=[], phone=[], userfile={}) to get lists when I have multiple form elements with the same name.

Why not be able to do something like this: web.input(_nolists=False) [I can't think of a good name] then in webapi.py input() line 278: add 1 line…

defaults.setdefault('_nolists', True)

and in utils.py storify() add:
  
_nolists = defaults.pop('_nolists')

… and ...

elif _nolists and not isinstance(defaults.get(key), dict):
    value = value[-1]

That forces returning FieldStorage objects (instead of their .value) when you do web.input(_nolists=False). I think thats ok for a long list of files. People usually need the file name in any case.

A cleaner way to add this might be an input() wrapper something like web.inputs() which always returns lists for fields with the same name.

Let me know what you think about something like that.

-hudlee [public@nilmail.com]

@anandology

Hudson Lee wrote on 2010-04-12:

https://bugs.launchpad.net/webpy/+bug/560278/+attachment/1309045/+files/webinputs.patch

This is how I would do it. Anyone like/hate this idea?

@anandology

Duplicate of #9.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment