-1

Hi I am working on a school project where I need to make an order form for a website using python and HTML. I am having trouble adding these:

if form.getvalue("interior"):
    print "<p>Interior Painting(s) quantity:", form["quantity"].value, "</p>"
    print "<p>You Cost is :$" ,int(form["quantity"].value)*2, ".00</p>"

else:
        print "<p>Interior Painting(s) ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("exterior"):
    print "<p>Exterior Painting quantity:", form["quantity2"].value, "</p>"
    print "<p>You Cost is :$" ,int(form["quantity2"].value)*1, ".00</p>"

else:
        print "<p>Exterior Painting(s) ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("pressure"):
    print "<p>Pressure Washing quantity:", form["quantity3"].value, "</p>"
    print "<p>You Cost is :$" ,int(form["quantity3"].value)*150, ".00</p>"
else:
       print "<p>Pressure Washings(s)ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("wood"):
    print "<p>Wood Finishing quantity:", form["quantity4"].value, "</p>"
    print "<p>You Cost is $" ,int(form["quantity4"].value)*3, ".00</p>"
else:
        print "<p>Wood Finsihings(s) ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("spraycan"):
    print "<p>Spray Can quantity:", form["quantity5"].value, "</p>"
    print "<p>You Cost is $" ,int(form["quantity5"].value)*10, ".00</p>"
else:
        print "<p>Spray Cans ordered: <b>0</b> <br /> Cost: <b>$0</b></p>" 

I am trying to add all the int(form[quantity..1..2].value all together and display a result after these. I have tried assigning the form[quantity].value to a varaible and adding them up but it isnt working. Also since getvalue only executes when the user selects the option, how can i go about doing this? Thanks.

FULL CODE

import cgi
form = cgi.FieldStorage()

# print HTTP/HTML header stuff
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>Order Form</title>
</head><body>
"""

# print HTML body using form data
print "<h1>Profesional Painters</h1>"
print "<h2>Customer Reciept</h2>"
print "<p>Customer Name:", form["customerName"].value, "</p>"
print "<p>Customer Email Address:", form["customerEmail"].value, "</p>"
print "<h2>Customer Address:</h2>"
print "<p>Street:", form["customerAdd"].value, "</p>"
print "<p>City:", form["customerCity"].value, "</p>"
print "<p>Province:", form["customerProv"].value, "</p>"
print "<p>Postal Code:", form["customerPostal"].value, "</p>"
print "<h2>Payment Information:</h2>"
print "<p>Card Type:", form["type1"].value, "</p>"
print "<p>Card Number: XXXX-XXXX-XXXX-", form["four4"].value, "</p>"
print "<p>Expiry Date:", form["expirt"].value, "</p>"

print "<h2>Products Ordered</h2>"

if form.getvalue("interior"):
    print "<p>Interior Painting(s) quantity:", form["quantity"].value, "</p>"
    print "<p>You Cost is :$" ,int(form["quantity"].value)*2, ".00</p>"

else:
        print "<p>Interior Painting(s) ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("exterior"):
    print "<p>Exterior Painting quantity:", form["quantity2"].value, "</p>"
    print "<p>You Cost is :$" ,int(form["quantity2"].value)*1, ".00</p>"

else:
        print "<p>Exterior Painting(s) ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("pressure"):
    print "<p>Pressure Washing quantity:", form["quantity3"].value, "</p>"
    print "<p>You Cost is :$" ,int(form["quantity3"].value)*150, ".00</p>"
else:
       print "<p>Pressure Washings(s)ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("wood"):
    print "<p>Wood Finishing quantity:", form["quantity4"].value, "</p>"
    print "<p>You Cost is $" ,int(form["quantity4"].value)*3, ".00</p>"
else:
        print "<p>Wood Finsihings(s) ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("spraycan"):
    print "<p>Spray Can quantity:", form["quantity5"].value, "</p>"
    print "<p>You Cost is $" ,int(form["quantity5"].value)*10, ".00</p>"
else:
        print "<p>Spray Cans ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("email"):
    print "<p>An email notification will be sent to ",form["customerEmail"].value, "</p>"

print "</body></html>"
4
  • 1
    This is where it becomes a mess, separate HTML from python, use a template language, like jinja2.
    – alecxe
    Commented Jul 31, 2014 at 2:22
  • Make HTML templates, put placeholders into it and render the templates with the appropriate context. See Templating.
    – alecxe
    Commented Jul 31, 2014 at 2:28
  • i dont really have time to do that stuff, can someone just help me with the problem? Commented Jul 31, 2014 at 2:30
  • can you post the complete code of your py script?
    – jiaoziren
    Commented Jul 31, 2014 at 2:36

1 Answer 1

0

Here's my take on your question, the logic is to allocate calculated values to variables so you can manipulate them for a sum.

q1 = int(form["quantity"].value)*2
q2 = int(form["quantity2"].value)*1
q3 = int(form["quantity3"].value)*150
q4 = int(form["quantity4"].value)*3
q5 = int(form["quantity5"].value)*10

if form.getvalue("interior"):
    print "<p>Interior Painting(s) quantity:", form["quantity"].value, "</p>"
    print "<p>You Cost is :$" ,q1, ".00</p>"

else:
    q1 = 0
    print "<p>Interior Painting(s) ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("exterior"):
    print "<p>Exterior Painting quantity:", form["quantity2"].value, "</p>"
    print "<p>You Cost is :$" ,q2, ".00</p>"

else:
    q2 = 0
    print "<p>Exterior Painting(s) ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("pressure"):
    print "<p>Pressure Washing quantity:", form["quantity3"].value, "</p>"
    print "<p>You Cost is :$" ,q3, ".00</p>"
else:
    q3 = 0   
    print "<p>Pressure Washings(s)ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("wood"):
    print "<p>Wood Finishing quantity:", form["quantity4"].value, "</p>"
    print "<p>You Cost is $" ,q4, ".00</p>"
else:
    q4 = 0
    print "<p>Wood Finsihings(s) ordered: <b>0</b> <br /> Cost: <b>$0</b></p>"

if form.getvalue("spraycan"):
    print "<p>Spray Can quantity:", form["quantity5"].value, "</p>"
    print "<p>You Cost is $" ,q5, ".00</p>"
else:
    q5 = 0
    print "<p>Spray Cans ordered: <b>0</b> <br /> Cost: <b>$0</b></p>" 

total = q1 + q2 + q3 + q4 + q5
print "<p>Total: ", total, "</p>"
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.