MCPcopy Create free account
hub / github.com/ActiveState/code / getform

Function getform

recipes/Python/286217_cgishell/recipe-286217.py:50–64  ·  view source on GitHub ↗

This function, given a CGI form, extracts the data from it, based on valuelist passed in. Any non-present values are set to '' - although this can be changed. (e.g. to return None so you can test for missing keywords - where '' is a valid answer but to have the field missing isn't.)

(valuelist, theform, notpresent='')

Source from the content-addressed store, hash-verified

48# Private functions and variables
49
50def getform(valuelist, theform, notpresent=''):
51 """This function, given a CGI form, extracts the data from it, based on
52 valuelist passed in. Any non-present values are set to '' - although this can be changed.
53 (e.g. to return None so you can test for missing keywords - where '' is a valid answer but to have the field missing isn't.)"""
54 data = {}
55 for field in valuelist:
56 if not theform.has_key(field):
57 data[field] = notpresent
58 else:
59 if type(theform[field]) != type([]):
60 data[field] = theform[field].value
61 else:
62 values = map(lambda x: x.value, theform[field]) # allows for list type values
63 data[field] = values
64 return data
65
66
67theformhead = """<HTML><HEAD><TITLE>cgi-shell.py - a CGI by Fuzzyman</TITLE></HEAD>

Callers 1

recipe-286217.pyFile · 0.70

Calls 2

mapFunction · 0.85
has_keyMethod · 0.45

Tested by

no test coverage detected