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 5To page 6current pageTo page 8
[previous] [next]

Usable Shopping Carts, Chapter 7: CC Validation and Verification

Data Center Architect
The Computer Merchant, Ltd
US-MA-chelsea

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


Here we make use of the date() and mktime() functions to display dropdowns from which the user can select the card expiration month and year. The latter is called as

mktime(hour, minute, second, month, day, year);

and returns a Unix timestamp which is equivalent to the number of seconds elapsed since 12:00:00 AM Universal Time on 01 January 1970, also known as the Unix Epoch. It's not a good idea to omit any of these 6 arguments, all of which should be integers; doing so can lead to unexpected results. The function can take an optional seventh argument to indicate whether or not the time and date are Daylight Saving Time--use a 1 for DST and a zero for standard time. The default is zero.

    <td class="cart" align="center">Month:<br />

      <select name="Expiration0Month_required">

          <option value=""

<?php 

  if( !isset($HTTP_POST_VARS["Expiration0Month_required"]) )

    echo " selected=\"selected\""; 

?>>[choose month:]</option>

<?php

This for() loop generates a set of 12 <option> tags whose values are the integers from 1 to 12, and whose text contains the three-letter abbreviations for the months in order ("Jan" to "Dec"). We use the same technique to set the selected option to the expiration month previously selected on page reload as we did for the State dropdown in the Address form seen earlier in this chapter:

    for ($m=1;$m<13;$m++)

    {

      $month = date ("M",mktime(0,0,0,$m,1,0));

      echo "<option value=\"$m\"";

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

           && 

           $HTTP_POST_VARS["Expiration0Month_required"] == $m)

        echo " selected=\"selected\"";

      echo ">$month</option>\n";

    }

?>

        </select>

    </td>

    <td class="cart" align="center">Year:<br />

      <select name="Expiration0Year_required">

        <option value=""

<?php if( !isset($HTTP_POST_VARS["Expiration0Year_required"]) )

        echo " selected=\"selected\""; 

?>>[choose year:]</option>

<?php

The dropdown for the card's year of expiration is generated in a similar fashion, except that we start with the current year and display options for it and the 5 years following. As most credit and bank cards are issued for 1 to 4 year periods, this should be a sufficient span of time:

    $thisyear = date("Y");

    for($y=0;$y<=5;$y++)

    {

      $theyear = $thisyear + $y;

      echo "<option value=\"$thisyear\"";

      if( isset($HTTP_POST_VARS["Expiration0Year_required"]) && $HTTP_POST_VARS["Expiration0Year_required"] == $thisyear)

        echo " selected=\"selected\"";

      echo ">$theyear</option>\n";

    }

?>

        </select>

    </td>

  </tr>

  <tr>

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

  </tr>

  <tr>

    <td class="cart" align="center">Card Number:<br />

      <input type="text" name="Credit0Card0Number_ccnumber_required" size="16"

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

    </td>

    <td class="cart" align="center">Zip Code where you receive your statement:<br />

      <input type="text" name="Cardholder0Zip0Code_uszip_required" size="10"

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

    </td>

  </tr>

  <tr>

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

  </tr>

  <tr>

    <td align="center">

      <input type="submit" name="cc_submit" class="search" value="Submit" />

    </td>

    <td align="center">

      <input type="reset" name="reset" class="search" value="Reset" />

    </td>

  </tr>

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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

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

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