[patch] html_select_date/time suffix

[email protected] (Sebastian Mendel) Wed, 13 Jun 2007 08:22:28 +0200
Newsgroups php.smarty.dev
Message-ID <[email protected]>
--------------040903020803090407070103
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Hi,

i created a patch for allowing specifying suffix additional to prefix

Code:
{html_select_date
    prefix='object[date]['
    suffix='][]'
    }


it allows for example

Code:
<select name="object[date][Day][]">...
<select name="object[date][Month][]">...
<select name="object[date][Year][]">...

this comes helpfull if you have more date selectors and need the [] at last
and not at start

$_REQUEST['date']['Day'][0]
$_REQUEST['date']['Month'][0]
$_REQUEST['date']['Year'][0]
$_REQUEST['date']['Day'][1]
$_REQUEST['date']['Month'][1]
$_REQUEST['date']['Year'][1]

instead of:

$_REQUEST['date'][0]['Day']
$_REQUEST['date'][1]['Month']
$_REQUEST['date'][2]['Year']
$_REQUEST['date'][3]['Day']
$_REQUEST['date'][4]['Month']
$_REQUEST['date'][5]['Year']

with field_array


-- 
Sebastian Mendel

www.sebastianmendel.de

--------------040903020803090407070103
Content-Type: text/plain;
 name="smarty_html_select_date_time_suffix.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="smarty_html_select_date_time_suffix.patch"

Index: libs/plugins/function.html_select_date.php
===================================================================
RCS file: /repository/smarty/libs/plugins/function.html_select_date.php,v
retrieving revision 1.36
diff -u -r1.36 function.html_select_date.php
--- libs/plugins/function.html_select_date.php	6 Mar 2007 20:13:55 -0000	1.36
+++ libs/plugins/function.html_select_date.php	11 Jun 2007 14:03:28 -0000
@@ -42,6 +42,7 @@
     require_once $smarty->_get_plugin_filepath('function','html_options');
     /* Default values. */
     $prefix          = "Date_";
+    $suffix          = "";
     $start_year      = strftime("%Y");
     $end_year        = $start_year;
     $display_days    = true;
@@ -87,6 +88,7 @@
     foreach ($params as $_key=>$_value) {
         switch ($_key) {
             case 'prefix':
+            case 'suffix':
             case 'time':
             case 'start_year':
             case 'end_year':
@@ -194,9 +196,9 @@
 
         $month_result .= '<select name=';
         if (null !== $field_array){
-            $month_result .= '"' . $field_array . '[' . $prefix . 'Month]"';
+            $month_result .= '"' . $field_array . '[' . $prefix . 'Month' . $suffix . ']"';
         } else {
-            $month_result .= '"' . $prefix . 'Month"';
+            $month_result .= '"' . $prefix . 'Month' . $suffix . '"';
         }
         if (null !== $month_size){
             $month_result .= ' size="' . $month_size . '"';
@@ -231,9 +233,9 @@
 
         $day_result .= '<select name=';
         if (null !== $field_array){
-            $day_result .= '"' . $field_array . '[' . $prefix . 'Day]"';
+            $day_result .= '"' . $field_array . '[' . $prefix . 'Day' . $suffix . ']"';
         } else {
-            $day_result .= '"' . $prefix . 'Day"';
+            $day_result .= '"' . $prefix . 'Day' . $suffix . '"';
         }
         if (null !== $day_size){
             $day_result .= ' size="' . $day_size . '"';
@@ -257,9 +259,9 @@
     if ($display_years) {
     	$field_separator_count++;
         if (null !== $field_array){
-            $year_name = $field_array . '[' . $prefix . 'Year]';
+            $year_name = $field_array . '[' . $prefix . 'Year' . $suffix . ']';
         } else {
-            $year_name = $prefix . 'Year';
+            $year_name = $prefix . 'Year' . $suffix;
         }
         if ($year_as_text) {
             $year_result .= '<input type="text" name="' . $year_name . '" value="' . $time[0] . '" size="4" maxlength="4"';
Index: libs/plugins/function.html_select_time.php
===================================================================
RCS file: /repository/smarty/libs/plugins/function.html_select_time.php,v
retrieving revision 1.14
diff -u -r1.14 function.html_select_time.php
--- libs/plugins/function.html_select_time.php	11 Oct 2005 16:22:56 -0000	1.14
+++ libs/plugins/function.html_select_time.php	11 Jun 2007 14:05:24 -0000
@@ -27,6 +27,7 @@
     require_once $smarty->_get_plugin_filepath('function','html_options');
     /* Default values. */
     $prefix             = "Time_";
+    $suffix             = "";
     $time               = time();
     $display_hours      = true;
     $display_minutes    = true;
@@ -49,6 +50,7 @@
     foreach ($params as $_key=>$_value) {
         switch ($_key) {
             case 'prefix':
+            case 'suffix':
             case 'time':
             case 'field_array':
             case 'all_extra':
@@ -88,9 +90,9 @@
             $hours[$i] = sprintf('%02d', $hours[$i]);
         $html_result .= '<select name=';
         if (null !== $field_array) {
-            $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
+            $html_result .= '"' . $field_array . '[' . $prefix . 'Hour' . $suffix . ']"';
         } else {
-            $html_result .= '"' . $prefix . 'Hour"';
+            $html_result .= '"' . $prefix . 'Hour' . $suffix . '"';
         }
         if (null !== $hour_extra){
             $html_result .= ' ' . $hour_extra;
@@ -114,9 +116,9 @@
         $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval);
         $html_result .= '<select name=';
         if (null !== $field_array) {
-            $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';
+            $html_result .= '"' . $field_array . '[' . $prefix . 'Minute' . $suffix . ']"';
         } else {
-            $html_result .= '"' . $prefix . 'Minute"';
+            $html_result .= '"' . $prefix . 'Minute' . $suffix . '"';
         }
         if (null !== $minute_extra){
             $html_result .= ' ' . $minute_extra;
@@ -141,9 +143,9 @@
         $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval);
         $html_result .= '<select name=';
         if (null !== $field_array) {
-            $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';
+            $html_result .= '"' . $field_array . '[' . $prefix . 'Second' . $suffix . ']"';
         } else {
-            $html_result .= '"' . $prefix . 'Second"';
+            $html_result .= '"' . $prefix . 'Second' . $suffix . '"';
         }
         
         if (null !== $second_extra){
@@ -165,9 +167,9 @@
     if ($display_meridian && !$use_24_hours) {
         $html_result .= '<select name=';
         if (null !== $field_array) {
-            $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';
+            $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian' . $suffix . ']"';
         } else {
-            $html_result .= '"' . $prefix . 'Meridian"';
+            $html_result .= '"' . $prefix . 'Meridian' . $suffix . '"';
         }
         
         if (null !== $meridian_extra){


--------------040903020803090407070103--