html_select_date patch

From: Date: Fri, 28 Feb 2003 18:38:19 +0000
Subject: html_select_date patch
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8305@lists.php.net to get a copy of this message
This patch will add the following to html_select_date: selected_year - sets the default selected year. selected_month - sets the default selected month. selected_day - sets the default selected day. I found the need to add these three new optional parameters to this function when I had to regenerate what a user previously selected. i.e. in a data entry page, if you return an error page you can now return the form with the values the user previously selected. Makes it easier to show the user what he/she has entered wrong like February 31 or something. This patch was made against Smarty-2.4.2. Best regards. And apologies if patches are not supposed to be posted here. -- _nimrod_a_abing_ PGP Public Key here: http://www.redberger.com/~abing/abing_at_redberger_dot_com.asc Key expires at Thu Nov 6 11:01:34 2003 PHT

--- function.html_select_date.php.orig 2003-03-01 01:52:42.000000000 +0800 +++ function.html_select_date.php 2003-03-01 02:18:11.000000000 +0800 @@ -60,6 +60,12 @@ $field_order = 'MDY'; /* String printed between the different fields. */ $field_separator = "\n"; + + /* Default selected values */ + $selected_day = null; + $selected_month = null; + $selected_year = null; + $time = time(); @@ -74,6 +80,9 @@ } // Now split this in pieces, which later can be used to set the select $time = explode("-", $time); + $selected_day = (!isset($selected_day) ? $time[2] : $selected_day); + $selected_month = (!isset($selected_month) ? $time[1] : $selected_month); + $selected_year = (!isset($selected_year) ? $time[0] : $selected_year); // make syntax "+N" or "-N" work with start_year and end_year if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) { @@ -123,7 +132,7 @@ $month_result .= smarty_function_html_options(array('output' => $month_names, 'values' => $month_values, - 'selected' => $month_values[$time[1]-1], + 'selected' => $month_values[$selected_month-1], 'print_result' => false), $smarty); @@ -155,7 +164,7 @@ $day_result .= '>'."\n"; $day_result .= smarty_function_html_options(array('output' => $days, 'values' => $day_values, - 'selected' => $time[2], + 'selected' => $selected_day, 'print_result' => false), $smarty); $day_result .= '</select>'; @@ -168,7 +177,7 @@ $year_name = $prefix . 'Year'; } if ($year_as_text) { - $year_result .= '<input type="text" name="' . $year_name . '" value="' . $time[0] . '" size="4" maxlength="4"'; + $year_result .= '<input type="text" name="' . $year_name . '" value="' . $selected_year . '" size="4" maxlength="4"'; if (null !== $all_extra){ $year_result .= ' ' . $all_extra; } @@ -195,7 +204,7 @@ $year_result .= '>'."\n"; $year_result .= smarty_function_html_options(array('output' => $years, 'values' => $years, - 'selected' => $time[0], + 'selected' => $selected_year, 'print_result' => false), $smarty); $year_result .= '</select>';
« previous php.smarty.general (#8305) next »