4
Better solution - use OOP: extend original class XoopsFormTextDateSelect and add parameter $autofill
class pfFormTextDateSelect extends XoopsFormTextDateSelect
{
/**
* Constructor
*
* @param string $caption Caption
* @param string $name "name" attribute
* @param int $size Size
* @param int,string $value Initial date (timestamp format) or English textual datetime description which can be converted to timestamp (see: strtotime PHP function)
* @param bool $autofill If $value is empty or not recognized textual datetime the form field filled current date ($autofill = true) or leave empty
*/
function pfFormTextDateSelect($caption, $name, $size = 15, $value = 0, $autofill = true)
{
// previous to PHP 5.1.0 you would compare with -1, instead of false
if ( strtotime($value) !== false OR strtotime($value) != -1 ) {
$value = strtotime($value);
}
if ( $autofill === true ) {
$value = !is_numeric($value) ? time() : intval($value);
$value = ($value == 0) ? time() : $value;
}
else {
$value = !is_numeric($value) ? '' : intval($value);
$value = ($value == 0) ? '' : $value;
}
$this->XoopsFormText($caption, $name, $size, 25, $value);
}
}
Moreover this class accepts English textual datetime description and convert it into a timestamp (see
http://php.net/manual/en/function.strtotime.php).
Example, this displays a later date by one day:
new pfFormTextDateSelect('', 'test', 10, '+1 day', false);
Empty field:
new pfFormTextDateSelect('', 'test', 10, '', false);