By: Chris

<!--- Credit Card Expiration.cfm custom tag --->
<!--- Make sure that user specified a name for the form field --->
<cfif NOT IsDefined("Attributes.FieldName")>
    <!--- No Name Was Specified, stop custom tag and ask that user specify field --->
    <font color="red" size="4">You did not specify a valid Expiration Month!</font>
    <cfabort>
</cfif>

<cfif NOT IsDefined("Attributes.FieldName2")>
    <!--- No Name Was Specified, stop custom tag and ask that user specify field --->
    <font color="red" size="4">You did not specify a valid Expiration Year!</font>
    <cfabort>
</cfif>

<!--- define a variable called "Attributes.DefaultCreditCardExp" to be Current Month --->
<cfif NOT IsDefined("Attributes.DefaultCreditCardExp")>
    <!--- No Default Credit Card Expiration Was Define, Set Default To Be Current Month --->
    <cfset Attributes.DefaultCreditCardExp = "01">
</cfif>

<!--- Now Create the Select Box With The Credit Card Expiration --->
<cfoutput>
    <select name="#Attributes.FieldName#">
        <cfloop from="1" to="12" index="i">
            <cfif i EQ "1" OR i EQ "2" OR i EQ "3" OR i EQ "4" OR i EQ "5" OR i EQ "6" OR i EQ "7" OR i EQ "8" OR i EQ "9">
                <option value="0#i#"<cfif Attributes.DefaultCreditCardExp eq "0#i#"> SELECTED</CFIF>>0#i#</option>
            <cfelse>
                <option value="#i#"<cfif Attributes.DefaultCreditCardExp eq "#i#"> SELECTED</CFIF>>#i#</option>
            </cfif> 
        </cfloop>
    </select>
    <select name=
"#Attributes.FieldName2#">
        <cfset this_yeardate2 = "#DateFormat(Now(),'yy')#">
        <cfset this_yeardate =
"#DateFormat(Now(),'yyyy')#">
        <option value="#this_yeardate2#"<cfif Attributes.DefaultCreditCardExp eq "#this_yeardate#"> SELECTED</CFIF>>#this_yeardate#</option>
        <cfloop from="1" to="5" index="j">
            <cfset next_year = dateAdd(
'yyyy', #j#, now())>
            <cfset next_yeardate =
"#DateFormat(next_year,'yyyy')#">
            <cfset next_yeardate2 =
"#DateFormat(next_year,'yy')#">
            <option value="#next_yeardate2#"<cfif Attributes.DefaultCreditCardExp eq "#next_yeardate2#"> SELECTED</CFIF>>#next_yeardate#</option>
        </cfloop>
    </select>
</cfoutput>

About This Tutorial
Author: Chris
Skill Level: Intermediate 
 
 
 
Platforms Tested: CF5
Total Views: 20,570
Submission Date: September 08, 2004
Last Update Date: June 05, 2009
All Tutorials By This Autor: 4
Discuss This Tutorial
Advertisement

Sponsored By...
Powered By...