Add server-side form validation to the order form in the bookstore case study. Check that the credit-card expiration date is after today’s date. If not, redirect the user to error.py with the message "Expired credit card." Also, make all fields in the form required fields. When the user does not supply data for all required fields, redirect the user back to order.py.

What will be an ideal response?


```
# Exercise 23.6: process.py
# Display thank you page to customer and delete session

import cgi
import time
import sys
import Session

# load session
try:
session = Session.Session()
except Session.SessionError, message: # invalid/no session ID
Session.redirect( "error.py?message=%s" % message )
sys.exit()

form = cgi.FieldStorage()
fields = [ "firstname", "lastname", "city", "state", "creditcard",
"zipcode", "phone", "street", "expires", "expires2" ]

# test for required fields
for field in fields:

if not form.has_key( field ):
Session.redirect( "order.py?ID=%s" % session.data[ "ID" ] )
sys.exit()

# test for expired credit card
month = int( time.strftime( "%m" ) )
year = int( time.strftime( "%Y" ) )
cardMonth = int( form[ "expires" ].value )
cardYear = int( form[ "expires2" ].value )

if ( cardYear < year ) or ( ( cardYear == year ) and \
( cardMonth <= month ) ):
Session.redirect( "error.py?message=Expired+credit+card." )
sys.exit()

# display content type and thankYou for specific client-type
content = open( "%s/thankYou.%s" % ( session.data[ "agent" ],
session.data[ "extension" ] ) )
pageData = session.data[ "content type" ] + content.read() % \
session.data[ "total" ]
content.close()

# delete session and display thank you page
session.deleteSession()
print pageData
```

Computer Science & Information Technology

You might also like to view...

_____ is a subset of e-commerce that involves electronic transactions between consumers using a third party to facilitate the process.

A. Business-to-business (B2B) e-commerce B. Business-to-consumer (B2C) e-commerce C. Consumer-to-business (C2B) e-commerce D. Consumer-to-consumer (C2C) e-commerce

Computer Science & Information Technology

A computer uses ____ operations to compare two values to see if they are equal to each other.

A. arithmetic B. logical C. grouping D. sorting

Computer Science & Information Technology

A new housing development extends 3 miles in one direction, makes a right turn, and then continues for 4 miles. A new road runs between the beginning and ending points of the development. What is the perimeter of the triangle formed by the homes and the road? What is the area of the housing development? The perimeter is __________ The area is __________

What will be an ideal response?

Computer Science & Information Technology

Documents organized in a reference format pull together all the information on a specific topic in a single section or chapter.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology