Obtaining the User's
Details (cont'd)
Page 13 of 22 -
Chapter 14
It's
smaller in terms of number of visible page elements, but more complex in terms
of validation as we have a radio group, a couple of select elements with dates
that need validating and a text box which must contain a valid number only.
Again, all of the validation functions are in the checkout_validate.inc
file we include inside the head of this page. Because there is more to check
in this form than on the personal details page form, a separate function has
been created to handle the onSubmit
event. Using functions defined in checkout_validate.inc,
it checks that the form is fully completed, the credit card number actually
contains numbers and that the card expiry date is valid. If any of these
checks fails then the form submit event is cancelled by returning false.
As in the previous page's onSubmit,
we are passing a reference to the form as a parameter of the function handling
the onSubmit.
<% @LANGUAGE="JScript" %>
<HTML>
<HEAD>
<!--#include file="checkoutvalidate.inc"-->
<SCRIPT LANGUAGE="JavaScript">
function frmCreditonsubmit(theForm)
{
// Check form fully filled in
if (checkCompleted(theForm) == false)
{
return false;
}
// Remove everything except numbers from CardNo
theForm.txtCardNo.VALUE =
numericOnly(theForm.txtCardNo.VALUE);
// If removing all but numbers results in nothing
then alert user
if (theForm.txtCardNo.VALUE == "")
{
alert("Your have entered your
credit card number incorrectly");
theForm.txtCardNo.focus();
return false;
}
// check credit card expiry date is valid
if (checkCardExpDate(theForm.cboExpMonth,theForm.cboExpYear)
== false)
{
return false;
}
}
</SCRIPT>
</HEAD>
<BODY>
<FONT FACE="Comic Sans MS" SIZE="3"
color="Navy">
<P align="center">
Please enter your credit card
details below.
</P>
</FONT>
<FORM METHOD=POST NAME="frmCredit" ACTION="checkoutconfirm.asp"
onSubmit="return
frmCreditonsubmit(this)">
|
The next form elements are
hidden input boxes that we populate using ASP script with the values the user
submitted in the personal details page. This is how we maintain state over the
course of the four pages involved in obtaining customer details except for the
items ordered which remain in the basket cookie until the very last page.