I CRE8

Site Navigation

Dynamic Credit Card Expiry Dates (PHP)

This information is generated via PHP. The current year is 2008 and the current month is 05

Copy the following piece of code into your snippets folder in Dreamweaver and just copy into any page that needs it, just remeber to change the names to suit existing forms if you are overwriting form elements automatically generated by DataAssist for example.

<?php 
$currentYear = date("Y");
$currentMonth = date("m");
?>
<select name="expMonth" id="expMonth">
<option value="01" <?php echo ($currentMonth == "01")?"selected":""; ?>>January</option>
<option value="02" <?php echo ($currentMonth == "02")?"selected":""; ?>>February</option>
<option value="03" <?php echo ($currentMonth == "03")?"selected":""; ?>>March</option>
<option value="04" <?php echo ($currentMonth == "04")?"selected":""; ?>>April</option>
<option value="05" <?php echo ($currentMonth == "05")?"selected":""; ?>>May</option>
<option value="06" <?php echo ($currentMonth == "06")?"selected":""; ?>>June</option>
<option value="07" <?php echo ($currentMonth == "07")?"selected":""; ?>>July</option>
<option value="08" <?php echo ($currentMonth == "08")?"selected":""; ?>>August</option>
<option value="09" <?php echo ($currentMonth == "09")?"selected":""; ?>>September</option>
<option value="10" <?php echo ($currentMonth == "10")?"selected":""; ?>>October</option>
<option value="11" <?php echo ($currentMonth == "11")?"selected":""; ?>>November</option>
<option value="12" <?php echo ($currentMonth == "12")?"selected":""; ?>>December</option>
</select>
<select name="expYear" id="expYear">
<?php 
$i = $currentYear;
while ($i <= ($currentYear+6)) // this gives you six years in the future
{
?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php 
$i++;
} 
?>
</select>