spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / carts / chap7 / 2 To page 1To page 2To page 3To page 4To page 5current pageTo page 7To page 8
[previous] [next]

Usable Shopping Carts, Chapter 7: CC Validation and Verification

Senior Lotus Notes Developer
AMS Staffing Solutions
US-MD-Baltimore

Justtechjobs.com Post A Job | Post A Resume
Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Now we take care of the case where either the credit card information form hasn't yet been submitted, or it has been but there were one or more validation errors. This is all quite similar to what we used for the Contact and Address form earlier in the chapter. If your credit card verification service requires more information on the cardholder, you can probably copy and paste the HTML for those form fields from checkout.php into this file, perhaps prefixing the field names with "Cardholder0" (e.g. Cardholder0Address0Line01_address_required) to avoid confusion, as we've done with the Cardholder Name and Cardholder ZIP Code fields already. The information in this form should probably not be saved anywhere unless you plan to set up user accounts and obtain permission to do so from each customer.

Do not save credit card account numbers unless you do via a secure connection and the database in which you save them can't be read from the Web.

  else

  {

?>

<h2>Credit Card Information</h2>

<p>All fields are required.</p>

<script src="../scripts/validate.js"></script>

<form action="<?php echo $PHP_SELF; ?>" method="POST" 

      onsubmit="return validate(this);">

<table width="80%" cellpadding="1" cellspacing="0" border="0">

  <tr>

    <th class="cart" colspan="2">Your name as it appears on the card:</th>

  </tr>

  <tr>

    <td class="cart" colspan="2" align="center">

      <input type="text" name="Cardholder0Name_required_alphabetic" size="50"

        value="<?php report("Cardholder0Name_required_alphabetic"); ?>" />    </td>

  </tr>

  <tr>

    <td colspan="2"><hr noshade="noshade" /></td>

  </tr>

  <tr>

    <th class="cart" colspan="2">Type of card:</th>

  </tr>

Note that there's some repetitive code here where we display the credit card types and accompanying radio buttons. Since we only use this code once and there's just three card types to worry, we don't bother with doing so here, but if we were to re-use this display elsewhere on the site, or if we began accepting more types of card, we might want to consider storing the types in an array or even in another database table.

  <tr>

    <td class="cart" align="right" width="50%">Visa</td>

    <td class="cart">

      <input type="radio" name="Credit0Card0Type_required"

        value="Visa"

<?php 

  if( isset($HTTP_POST_VARS["Credit0Card0Type_required"]) 

      && 

      $HTTP_POST_VARS["Credit0Card0Type_required"] == "Visa" )

    echo " checked=\"checked\""; 

?> />

    </td>

  </tr>

  <tr>

    <td class="cart" align="right">MasterCard</td>

    <td class="cart">

      <input type="radio" name="Credit0Card0Type_required"

        value="MasterCard"
<?php if( isset($HTTP_POST_VARS["Credit0Card0Type_required"]) && $HTTP_POST_VARS["Credit0Card0Type_required"] == "MasterCard" ) echo " checked=\"checked\""; ?> /> </td> </tr> <tr> <td class="cart" align="right">American Express</td> <td class="cart"> <input type="radio" name="Credit0Card0Type_required" value="American Express" <?php if( isset($HTTP_POST_VARS["Credit0Card0Type_required"]) && $HTTP_POST_VARS["Credit0Card0Type_required"] == "American Express" ) echo " checked=\"checked\""; ?> /> </td> </tr> <tr> <td colspan="2"><hr noshade="noshade" /></td> </tr> <tr> <th class="cart" colspan="2">Expiration date:</th> </tr> <tr>

home / programming / carts / chap7 / 2 To page 1To page 2To page 3To page 4To page 5current pageTo page 7To page 8
[previous] [next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

Created: December 26, 2002
Revised: December 26, 2002

URL: http://webreference.com/programming/carts/chap7/2/6.html