|
WebKeystone Example 3: Creating a form with multiple selectible items
The Form
The Files
<FORM METHOD="POST" ACTION="/wkstone/webkeystone.py">
<INPUT TYPE="HIDDEN" NAME="UserID" VALUE="biz_webkeystone">
<INPUT TYPE="HIDDEN" NAME="Profile" VALUE="examples/example3.prof">
<P><CENTER><FONT SIZE=+1><B>Sunny's Flower Shop</B></FONT></CENTER>
<CENTER><P>Please select flowers from the list below, and
<BR> indicate a quantity for each selection:</CENTER>
<CENTER><TABLE BGCOLOR=#ffffcc WIDTH=400 BORDER=0>
<TR><TD WIDTH=100>
<INPUT TYPE=CHECKBOX NAME="ItemNames.lst" VALUE="Roses">Roses
</TD>
<TD WIDTH=100>Quantity:<INPUT TYPE=TEXTBOX NAME="Quantities.vInt" SIZE=3>
</TD>
</TR>
<TR><TD WIDTH=100>
<INPUT TYPE=CHECKBOX NAME="ItemNames.lst" VALUE="Daffodils">Daffodils
</TD>
<TD WIDTH=100>Quantity:<INPUT TYPE=TEXTBOX NAME="Quantities.vInt" SIZE=3>
</TD>
</TR>
<TR><TD WIDTH=100>
<INPUT TYPE=CHECKBOX NAME="ItemNames.lst" VALUE="Carnations">Carnations
</TD>
<TD WIDTH=100>Quantity:<INPUT TYPE=TEXTBOX NAME="Quantities.vInt" SIZE=3>
</TD>
</TR>
<TR><TD WIDTH=100>
<INPUT TYPE=CHECKBOX NAME="ItemNames.lst" VALUE="Daisies">Daisies
</TD>
<TD WIDTH=100>Quantity:<INPUT TYPE=TEXTBOX NAME="Quantities.vInt" SIZE=3>
</TD>
</TR>
</TABLE></CENTER>
Email Address <I>(Optional)</I>:
<INPUT TYPE=TEXT NAME="Email.vEmail" SIZE=30><BR>
<INPUT TYPE=SUBMIT VALUE="Order!">
</FORM>
#
# Name : example3.prof
#
# Description : WebKeystone script that illustrates how
# to handle lists on an ordering form.
#
# Check for correctness of email address
IF "Email" in ErrorVal
RETURN RAW "Sorry, your email address is incorrect. Please go back and correct it."
# Remove all blank values from the list named 'Quantities'
IF f.some(Quantities)
FILTER
Quantities
ELSE
Quantities = []
# Check to see if the list named 'ItemNames' exists. Since the list is
# created with checkboxes, there is a possibility that the list will not
# exist.
IF exist('ItemNames')
# Make sure the number of items matches the number of quantities.
IF len(Quantities) != len(ItemNames)
RETURN 'examples/example3Fail.html'
ELSE
# Send email if an email address was entered.
IF len(Email) != 0
MAIL
TO Email
FROM 'sunnysflowers@webkeystone.com'
SUBJECT 'Your Order!'
BODY 'examples/example3Mail.txt'
RETURN 'examples/example3Return.html'
ELSE
RETURN 'examples/example3Fail.html'
# # Template to display the item name and quantity. # NOTE: the '\n' and '\t' are for formatting. These do not affect the HTML. template = '<B>Flower:</B>%(1)s, <B>Quantity:</B>%(2)s<BR>\n\t\t' #- <H3>You requested these flowers:</H3> <P> <UL> %(ItemNames,Quantities,template)s </UL> <H2>Thank you for your order!</H2> |
<H2>Sorry, you have entered an incorrect Item/Quantity combination</H2> <H3>Please click "Back" on your browser to return to the form, make sure you have chosen a quantity for each flower selected, and resubmit the form.</H3> <H2>Thank You!</H2> |
# # Template for order details: template = 'FLOWER: %(1)s, QUANTITY: %(2)s\n' #- We've received your order! Please verifiy that it is correct. %(ItemNames,Quantities,template)s Thanks very much! Sunny President & Founder of Sunny's Flowers |
| Previous Example | Next Example | Table of Contents |
Updated 2-August-99
|
|
|
|
|
| WebKeystone is a product of Townsend Software, Inc. ©1998 - 2001 Townsend Software, Inc. All rights reserved. |