0

Hi,

Need to do a project where the data from a HTML form is sent to Python, and then repackaged and sent back out as HTML. Problem is, I'm having issues with Python.

When I run the form information with Python, I get this error:

There was an error with your script and it didn't exit properly.

This was its output:

Content-type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>Receipt</title>
</head><body>

<p>Name: Kurtis Smejkal </p>
<p>Email:
Traceback (most recent call last):
File "/home/ksmejkal/public_html/assignment3/order.py", line 36, in <module>
print "<p>Email:", (form["email"].value), "</p>"
AttributeError: 'list' object has no attribute 'value'

And this is the whole entirety of my Python code

import cgi

#############################
# Name: Kurtis Smejkal
# Date: 2010-07-28
# Description: Takes the users name, and age. Hypothesizes how old said user
# will be in one year.
#############################

#############################
#Program Logic
#############################

#Grab the variables being passed in via CGI and store it in the dictionary
form = cgi.FieldStorage()

# Processing
# Namely, grab the name and the age, and then add one year to said age

#############################
#HTML Response page
#############################

#
print """Content-type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>Receipt</title>
</head><body>
"""

# print HTML body using form data
print "<p>Name:", (form["name"].value), "</p>"
print "<p>Email:", (form["email"].value), "</p>"
print "<p>Mailing Address:", (form["address"].value), "</p>"
print "<p>City:", (form["city"].value), "</p>"
print "<p>Province:", (form["province"].value), "</p>"
print "<p>Postal Code:", (form["postalcode"].value), "</p>"
print "<p>Credit Card Type:", (form["credittype"].value), "</p>"
print "<p>Credit Card Number:", (form["ccnumber"].value), "</p>"
print "<p>Expiration Date:", (form["expdate"].value), "</p>"
print "<p>This is what you entered into the second text box:</p>"
print "</body></html>"

Finally, the link to the html form itself.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Beat_Slayer
0

If the submitted form data contains more than one field with the same name, the object retrieved by form[key] is not a FieldStorage or MiniFieldStorage instance but a list of such instances. Similarly, in this situation, form.getvalue(key) would return a list of strings. If you expect this possibility (when your HTML form contains multiple fields with the same name), use the getlist() function, which always returns a list of values (so that you do not need to special-case the single item case).

Source

I guess you have more than one field.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.