Self-adjusting credit card expiration in dropdown menu

I’m interested in doing something like this example from CakePHP, so I don’t have to update my forms every year. Anyone know how to do this in regular old PHP?


This is easy to do using the date function. Since expiration must always be current year or higher, you can simply retrieve current year and go from there.

For ($i= date(‘Y’); $i <= date(‘Y’)+7; $i++)
echo $i;

Thanks, that put me on the right track. I just created 10 options, in this format:

<option value="<?php echo date('y'); ?>" <?php if((isset($_POST['CCYear'])) && ($_POST["CCYear"]==date('y'))){echo "selected=\\"selected\\""; ?><?php } ?>><?php echo date('Y'); ?></option>
<option value="<?php echo date('y')+1; ?>" <?php if((isset($_POST['CCYear'])) && ($_POST["CCYear"]==date('y')+1)){echo "selected=\\"selected\\""; ?><?php } ?>><?php echo date('Y')+1; ?></option>

So the form self-updates, and the form data is persistent after server-side error-checking.