More flexible html_select_date

From: Date: Fri, 24 Aug 2001 17:37:59 +0000
Subject: More flexible html_select_date
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1381@lists.php.net to get a copy of this message
Hi! I've modified the {html_select_date} function quite a bit. I've introduced a number of new options which may be passed. /* <select size>'s of the different <select> tags */ /* If not set, no size is printed */ $day_size = NULL; $month_size = NULL; $year_size = NULL; /* Unparsed arguments common to *ALL* the <select>/<input> tags */ /* An example might be in the template: all_args='class="foo"' */ $all_args = NULL; /* Seperate arguments for the tags */ $day_args = NULL; $month_args = NULL; $year_args = NULL; /* Order in which to display the fields */ /* "D" -> day, "M" -> month, "Y" -> year */ $date_order = 'MDY'; /* String printed between the different fields */ $field_sep = "\n"; This was, because I needed more flexibility for the select boxes and because the fields were displayed in the wrong order for my country (ie. it was month/day/year, but day/month/year is used here). Please find attached the diff to the Smarty.addons.php class and the documentation (x977.htm). Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.digitalprojects.com | http://www.iso-top.de iso-top.de - Die günstige Art an Linux Distributionen zu kommen Uptime: 10 hours 35 minutes

--- Smarty.addons.php.Original Fri Aug 24 18:15:08 2001 +++ Smarty.addons.php Fri Aug 24 18:55:50 2001 @@ -304,12 +304,30 @@ $month_format = "%B"; $day_format = "%02d"; $year_as_text = false; + /* <select size>'s of the different <select> tags */ + /* If not set, no size is printed */ + $day_size = NULL; + $month_size = NULL; + $year_size = NULL; + /* Unparsed arguments common to *ALL* the <select>/<input> tags */ + /* An example might be in the template: all_args='class="foo"' */ + $all_args = NULL; + /* Seperate arguments for the tags */ + $day_args = NULL; + $month_args = NULL; + $year_args = NULL; + /* Order in which to display the fields */ + /* "D" -> day, "M" -> month, "Y" -> year */ + $date_order = 'MDY'; + /* String printed between the different fields */ + $field_sep = "\n"; extract(func_get_arg(0)); $time = smarty_make_timestamp($time); + $date_order = strtoupper($date_order); - $html_result = ""; + $html_result = $month_result = $day_result = $year_result = ""; if ($display_months) { $month_names = array(); @@ -317,12 +335,22 @@ for ($i = 1; $i <= 12; $i++) $month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000)); - $html_result .= '<select name="'.$prefix.'Month">'."\n"; - $html_result .= smarty_func_html_options(array('output' => $month_names, - 'values' => range(1, 12), - 'selected' => strftime("%m", $time), - 'print_result' => false)); - $html_result .= "</select>\n"; + $month_result .= '<select name="'.$prefix.'Month"'; + if (NULL !== $all_args){ + $month_result .= ' ' . $all_args; + } + if (NULL !== $month_args){ + $month_result .= ' ' . $month_args; + } + if (NULL !== $month_size){ + $month_result .= ' size="' . $month_size . '"'; + } + $month_result .= '>'."\n"; + $month_result .= smarty_func_html_options(array('output' => $month_names, + 'values' => range(1, 12), + 'selected' => strftime("%m", $time), + 'print_result' => false)); + $month_result .= '</select>'; } if ($display_days) { @@ -330,27 +358,72 @@ for ($i = 0; $i < count($days); $i++) $days[$i] = sprintf($day_format, $days[$i]); - $html_result .= '<select name="'.$prefix.'Day">'."\n"; - $html_result .= smarty_func_html_options(array('output' => $days, - 'values' => range(1, 31), - 'selected' => strftime("%d", $time), - 'print_result' => false)); - $html_result .= "</select>\n"; + $day_result .= '<select name="'.$prefix.'Day"'; + if (NULL !== $all_args){ + $day_result .= ' ' . $all_args; + } + if (NULL !== $day_args){ + $day_result .= ' ' . $day_args; + } + if (NULL !== $day_size){ + $day_result .= ' size="' . $day_size . '"'; + } + $day_result .= '>'."\n"; + $day_result .= smarty_func_html_options(array('output' => $days, + 'values' => range(1, 31), + 'selected' => strftime("%d", $time), + 'print_result' => false)); + $day_result .= '</select>'; } if ($display_years) { if ($year_as_text) { - $html_result .= '<input type="text" name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">'; + $year_result .= '<input type="text" '; + if (NULL !== $all_args){ + $year_result .= ' ' . $all_args; + } + if (NULL !== $year_args){ + $year_result .= ' ' . $year_args; + } + $year_result .= 'name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">'; } else { $years = range($start_year, $end_year); - $html_result .= '<select name="'.$prefix.'Year">'."\n"; - $html_result .= smarty_func_html_options(array('output' => $years, + $year_result .= '<select name="'.$prefix.'Year"'; + if (NULL !== $all_args){ + $year_result .= ' ' . $all_args; + } + if (NULL !== $year_args){ + $year_result .= ' ' . $year_args; + } + if (NULL !== $year_size){ + $year_result .= ' size="' . $year_size . '"'; + } + $year_result .= '>'."\n"; + $year_result .= smarty_func_html_options(array('output' => $years, 'values' => $years, 'selected' => strftime("%Y", $time), 'print_result' => false)); - $html_result .= "</select>\n"; + $year_result .= '</select>'; } + } + + // Loop thru the date_order field + for ($i = 0; $i <= 2; $i++){ + $c = substr($date_order, $i, 1); + switch ($c){ + case 'D': + $html_result .= $day_result; + break; + case 'M': + $html_result .= $month_result; + break; + case 'Y': + $html_result .= $year_result; + break; + } + // Add the field seperator + $html_result .= $field_sep; } print $html_result; --- x977.htm.Original Fri Aug 24 18:57:26 2001 +++ x977.htm Fri Aug 24 19:35:30 2001 @@ -1115,6 +1115,249 @@ VALIGN="TOP" >whether or not to display the year as text</TD ></TR +><TR +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>day_size</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>string</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>No</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Unset</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Size to display the day select box in. If unset, no size="" parameter is printed</TD +></TR +><TR +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>month_size</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>string</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>No</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Unset</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Size to display the month select box in. If unset, no size="" parameter is printed</TD +></TR +><TR +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>year_size</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>string</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>No</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Unset</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Size to display the year select box in. If unset, no size="" parameter is printed. Ignored, if year_as_text is set</TD +></TR +><TR +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>all_args</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>string</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>No</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Unset</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Additional arguments to all the &gt;select&lt;/&gt;input&lt; tags. These arguments are printed as-is. Eg. in the template might be all_args='class="foo" id="yo"', which would then assign 'class="foo" id="yo"' to all the tags.</TD +></TR +><TR +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>day_args</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>string</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>No</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Unset</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Additional arguments to the day select box</TD +></TR +><TR +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>month_args</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>string</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>No</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Unset</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Additional arguments to the month select box</TD +></TR +><TR +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>year_args</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>string</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>No</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Unset</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Additional arguments to the year select box</TD +></TR +><TR +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>date_order</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>string</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>No</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>MDY</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>Order in which the fields are to be displayed. Possible values are all combinations of the letters D, M, Y. The letters stand for day (D), month (M) and year (Y)</TD +></TR +><TR +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>field_sep</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>string</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>No</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>\n</TD +><TD +WIDTH="20%" +ALIGN="LEFT" +VALIGN="TOP" +>String which is to be printed between all the fields. The default is a line break.</TD +></TR ></TBODY ></TABLE ><P @@ -3631,4 +3874,4 @@ ></DIV ></BODY ></HTML -> \ No newline at end of file +>
« previous php.smarty.general (#1381) next »