cgi and form NEED HELP!

Paul Boddie paul at boddie.net
Mon Oct 7 12:03:11 EDT 2002


"CheapSkate" <gua81 at XXXyahoo.com> wrote in message news:<anqlql$7be$1 at lust.ihug.co.nz>...
> hi, need a little help here.
> I'm having a list of items with checkboxses in them.
> the name attribute is unknow for each one(generated automatically).
> 
> now what I want to do is that
> in the cgi.FieldStorage(), I want it to contain all the names of the checked
> boxes.
> any idea?

That means that inside a single field in the FieldStorage object, you
want a list of all the items where a checkbox was selected.

> Here's the code for the checkbox:
> print '<input type="checkbox" name="%s" size="20"><a href=%s>%s</a></td>'%
> (filename, fullname, filename)
> 
> where filename is the filename of the file e.g apple
> and fullname is the fullpath to the file e.g C:\windows\desktop\apple

Since you're probably varying the filename and fullname for each
generated checkbox, this won't satisfy that criteria I gave above -
each checkbox in this case will have a different "name" attribute, and
you therefore won't get all the filenames in a single field entry from
FieldStorage. Instead, you'll get a single entry for each filename in
the FieldStorage object with a value of "on" (or whatever the HTML
forms standard says) associated with it, if the checkbox for that
filename was selected.

What you need to do is to choose a common name for all the checkboxes
and then to put the filename into the "value" attribute for each
checkbox, like this:

  print '<input type="checkbox" value="%s" name="files"><a
href=%s>%s</a></td>'% (filename, fullname, filename)

Then, under the entry for "files" (in this case) in the FieldStorage
object, you'll get a list of filenames whose checkboxes were selected.

Paul



More information about the Python-list mailing list