Zope ZPT Credit card expiration date HTML fields

You can leverage the DateTime object to create a month and year dropdown which default to the current month and year.

It also allows you to populate the year dropdown with only current and future years.
<div class="field" tal:define="error errors/cc_date|nothing" tal:attributes="class python:test(error, 'field error', 'field')">
	<label for="cc_exp_month">Exp. Date</label>
	<div tal:content="error">Validation error output</div>
	<select name="cc_exp_month" id="cc_exp_month" tal:define="month python:DateTime().month()">
		<tal:loop repeat="option python:range(1,13)">
			<option tal:attributes="value python: '%02d' % (option); selected python: (int(request.get('cc_exp_month', month)) == option and 'selected' or '')" tal:content="python: '%02d' % (option)" />
	<select name="cc_exp_year" id="cc_exp_year" tal:define="year python:DateTime().year()">
		<tal:loop repeat="option python:range(year,year + 16)">
			<option tal:attributes="value option; selected python: (int(request.get('cc_exp_year', '0')) == option and 'selected' or '')" tal:content="option" />
Posted by
Snippet Viewed 1355 times.

Share your Zope ZPT code snippets:

  • Get some recognition & link back to your site.


Submit | Browse

Most Recent zope zpt snippets

Most Viewed