Credit Card Display Forms in ASP/SQL--Part 1 of Chapter 7 from Usable Shopping Carts (2/3)
[previous] [next] |
Usable Shopping Carts, Chapter 7: CC Validation and Verification
Asp/SQL Server
Unlike PHP we do not have to worry about abandoning the Session object because we have moved the user over to
the secure server. The generalized format for this page (OnlineForm.asp) is similar to the address screen. There
are two primary procedures ValidateForm() and BuildForm(). In addition there is a function CheckCCNumLuhn() that is used as a
simple credit card number validator; we will cover this later in the chapter.
The base code for the page is a simple statement that determines the page state and directs to the appropriate subprocedure:
<%
If lcase(Request.Form("submit")) = "submit" Then
ValidateForm()
Else
BuildForm()
End IF
%>
We will begin with the ValidateForm() subprocedure:
Sub ValidateForm()
Dim boolFormIsValid 'as Boolean
boolFormIsValid = true
If Len(Request.Form("ccname")) < 1 Then boolFormIsValid = False
If Len(Request.Form("cctype")) < 1 Then boolFormIsValid = False
If Cint(Request.Form("ccmonth")) < 1 Then boolFormIsValid = False
If Cint(Request.Form("ccyear")) < 1 Then boolFormIsValid = False
If Len(Request.Form("ccnumber")) < 1 Then boolFormIsValid = False
If Len(Request.Form("cczip")) < 1 Then boolFormIsValid = False
If Not CheckCCNumLuhn(Request.Form("ccnumber")) Then boolFormIsValid = False
If Not boolFormIsValid Then
BuildForm()
Else
'This is where you pass the information to Merchant account interface
Response.write("Information submitted to merchant account.")
End If
End Sub
Unlike the address page, we do not have any regular expressions to validate
user input. For almost all of the inputs, we simply verify that the user entered
some data. The one exception is the credit card number. An additional function
to perform a Luhn check on the credit card number has been created and the
card number is passed to that. The information on the Luhn formula will be
discussed further in this chapter. If the form is valid, this would be the
point at which the information should be passed over to the merchant account
interface to be run against the entered credit card. In the event that the
form input is invalid, then the BuildForm() procedure is called
and any errors are noted for the user to correct.
The BuildForm() procedure follows
the same generalized format as the one in the address page. The code is written
to output the form, and in the case of submission, to display the error information
necessary to alert the user to problem data in the form:
Sub BuildForm()
If Request.Form("Submit") = "Submit" Then
blnShowErrors = true
Else
blnShowErrors = false
End IF
%>
The procedure begins by detecting whether it was called with a submit event
or not. In the event that the form was submitted back to the page, the flag
blnShowErrors is set to true:
<h1>Credit Card Information</h1>
<p>All Fields Are Required.</p>
<form name="CCForm" action="OnlineForm.asp" method=POST>
<p align=center><b>Your name as it appears on the card</b><br>
<input type="text" name="ccname" value="<%=Request.Form("ccname")%>" size=60>
<%if blnShowErrors AND Len(Request.Form("ccname")) < 1 Then response.write("<span class=""error"">Please Enter Your Name</span>")%>
</p><hr>
<p align=center><b>Type of Card</b><br>
Initially we establish the page and form specific information. In addition, we have the validation information for the form's first field.
<table width=50% cellspacing=2 cellpadding=0>
<tr><td align=right>Visa</td><td><input type="radio" name="cctype" value="visa" <%if request.form("cctype")="visa" then response.write("checked")%>><br></td></tr>
<tr><td align=right>MasterCard</td><td><input type="radio" name="cctype" value="mc" <%if request.form("cctype")="mc" then response.write("checked")%>><br></td></tr>
<tr><td align=right>American Express</td><td><input type="radio" name="cctype" value="amex" <%if request.form("cctype")="amex" then response.write("checked")%>><br></td></tr>
</table></p><hr>
[previous] [next] |
Created: December 18, 2002
Revised: December 18, 2002
URL: http://webreference.com/programming/carts/chap7/1/2.html

Find a programming school near you