Credit Card Display Forms in ASP/SQL--Part 1 of Chapter 7 from Usable Shopping Carts (3/3)
[previous] |
Usable Shopping Carts, Chapter 7: CC Validation and Verification
Next we handle the credit card type. This segment of the form is a collection
of radio buttons. The primary item to remember is
that radio buttons have a "checked" status, so when outputting the
form, we need to make sure that the validation sets this status correctly.
<p align=center><b>Expiration Date</b></p>
<table width=100% cellspacing=5 cellpadding=0>
<tr><td align=center>Month</td><td align=center>Year</td></tr>
<tr>
<td align=center>
<select name="ccmonth">
<option value=0>[Choose Month]
<%
Dim arrMonths
arrMonths = array("January", "February",
"March", "April",
"May", "June",
"July", "August",
"September", "October",
"November", "December")
For i = 0 to UBound(arrMonths)
Response.Write("<option value=" & (i+1))
If Cint(Request.Form("ccmonth")) = (i+1) then response.write(" selected ")
Response.write(">" & arrMonths(i) & vbcrlf)
Next
%>
</select>
<%if blnShowErrors AND Cint(Request.Form("ccmonth")) < 1 Then response.write("<span class=""error"">Please Select the expiration month</span>")%>
</td>
The expiration information for a credit card is critical. We need to make sure that this is captured correctly. The first field is expiration month. There are a number of different methods for outputting this information. It may either be stored within our database or, in this example, an array at page level. To output the options for the select the month array is looped across similar to how we would loop across a recordset. In addition, there is a check to set the correct selected value in the event of a submit.
<td align=center><select name="ccyear">
<option value=0>[Choose Year]
<%
Dim thisYear
thisYear = Year(Now)
For i = 0 to 4
Response.Write("<option value=" & (thisYear+i))
If Cint(Request.Form("ccyear")) = (thisYear + i) Then Response.write(" selected ")
Response.Write(">" & (thisYear+i))
Next
%>
</select>
<%if blnShowErrors AND Cint(Request.Form("ccyear")) < 1 Then response.write("<span class=""error"">Please Select the expiration year</span>")%>
</td></tr>
The year is handled in a similar fashion to the month. Since years, unlike months, are an indirect starting point, the code grabs the current year and then builds the select based on adding five years to the current year. Again, we have inserted the validation information into the loop to set the proper value for the select.
<tr><td colspan=2><hr></td></tr>
<tr><td align=center>Card Number</td>
<td align=center>Zip Code where you recieve your statement</td>
</tr><tr>
<td align=center>
<input type="text" name="ccnumber" value="<%=request.form("ccnumber")%>">
<%If blnShowErrors AND len(request.form("ccnumber"))<1 AND NOT CheckCCNumLuhn(Request.Form("ccnumber"))Then
response.write("<span class=""error"">Please verify your credit card number</span>")
End If %>
</td>
<td align=center>
<input type="text" name="cczip" value="<%=request.form("cczip")%>">
<%if blnShowErrors AND Len(Request.Form("cczip")) < 1 Then response.write("<span class=""error"">Please enter your zip code</span>")%>
</td>
</tr><tr><td colspan=2><hr></td></tr>
<tr><td align=center><input type="submit" name="submit" value="Submit"></td>
<td align=center><input type="reset" name="reset" value="Reset"></td></tr>
</table></form>
Finally the form takes the input of the credit card number and the user's zip code. You'll note that we invoke the Luhn function again in this section when determining whether or not to output an error message for the credit card information. Finally the form is terminated with the appropriate submit button functionality.
[previous] |
Created: December 18, 2002
Revised: December 18, 2002
URL: http://webreference.com/programming/carts/chap7/1/3.html

Find a programming school near you