I think it would be a great addition to the FormHelper? to have the ability to create a select_day_tag, select_month_tag, select_year_tag and a consolodated select_date_tag helper. I coded up the preliminary methods for this (below), and have tested them with the latest beta.
Things I haven't done
- I did not add I18N for the date formats
- Built the function to convert the select_date_tag to a timestamp for insertion
- Accounted for dates pre-1970 (I recommend the ADODB Time Library).
Let me know if I can help you with any of the code here.
function select_day_tag($name, $value, $options = "")
{
$data = array();
for ($x = 1; $x < 32; $x++)
{
$data[((strlen($x < 2)) ? 0 . $x : $x)] = date($output, strtotime(date("Y") . "-" . 12 . "-" . $x));
}
$option_tags = options_for_select($data, $value);
return select_tag($name, $option_tags, $options);
}
function select_month_tag($name, $value, $options = "")
{
$data = array();
for ($x = 1; $x < 13; $x++)
{
$data[((strlen($x < 2)) ? 0 . $x : $x)] = date("n", strtotime(date("Y") . "-" . ((strlen($x < 2)) ? 0 . $x : $x) . "-" . 01));
}
$option_tags = options_for_select($data, $value);
return select_tag($name, $option_tags, $options);
}
function select_year_tag($name, $value, $options = "")
{
$options['year_start'] = (!empty($options['year_start']) AND is_numeric($options['year_start'])) ? $options['year_start'] : date("Y") - 10;
$options['year_end'] = (!empty($options['year_end']) AND is_numeric($options['year_end'])) ? $options['year_end'] : date("Y");
$data = array();
for ($x = $options['year_start']; $x < ($options['year_end'] + 1); $x++)
{
$data[$x] = $x;
}
unset($options['year_start'], $options['year_end']);
$option_tags = options_for_select($data, $value);
return select_tag($name, $option_tags, $options);
}
function select_date_tag($name, $value, $options = "")
{
//Culture is not implemented yet (default for now is mm/dd/yyyy)
$day = ($options['discard_day'] != true) ? select_day_tag($name . '_day', date('d', strtotime($value)), $options) : "";
if (isset($options['discard_day']))
{
unset($options['discard_day']);
}
$month = select_month_tag($name . '_month', date('m', strtotime($value)), $options);
$year = select_year_tag($name . '_year', $value, $options);
return $month . $day . $year;
}