<?php
require_once( 'HTML/QuickForm.php' );
define( '_SELECT_ERROR', '%sãé¸æãã¦ãã ããã' );
define( '_VALID_ERROR', 'æ£ãã%sãå
¥åãã¦ãã ããã' );
define( '_AS_YOU_LIKE', 3 );
class MyForm extends HTML_QuickForm
{
function MyForm()
{
parent::HTML_QuickForm();
$this->registerElementType( 'date_jp',
'/path/to/jp.php',
'HTML_QuickForm_date_jp' );
}
function addDate( $name, $label )
{
$option = array(
'minYear' => date( 'Y' ) - _AS_YOU_LIKE,
'maxYear' => date( 'Y' ) + _AS_YOU_LIKE,
'format' => 'Y å¹´ m æ d æ¥',
'addEmptyOption' => true,
'emptyOptionValue' => '',
'emptyOptionText' => '--'
);
$default = array(
$name => array(
'Y' => date( 'Y' ),
'm' => date( 'm' ),
'd' => date( 'd' ),
'H' => date( 'H' ),
'i' => '0'
)
);
$this->addElement( 'date_jp', $name, $label, $option );
$this->setDefaults( $default );
$this->addGroupRule( $name, sprintf( _SELECT_ERROR, $label ), 'required' );
$this->registerRule( 'isValidDate', 'callback', '_isValidDate', $this );
$this->addRule( $name, sprintf( _VALID_ERROR, $label ), 'isValidDate', true );
}
function _isValidDate( $vals )
{
if ( checkdate( $vals['m'], $vals['d'], $vals['Y'] ) ) {
return true;
}
return false;
}
}
?>