html_select_date alteration

From: Date: Mon, 31 Mar 2003 07:35:53 +0000
Subject: html_select_date alteration
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-1053@lists.php.net to get a copy of this message
I had need to make changes to the html_select_date plugin. Specifically, I needed the ability to have zero date selected if the date I was passing was in fact empty. If I didn't, then when my form was submitted I would have got todays date - I needed to keep that date empty by default if it was originally empty and with the current setup that's not possible. I noticed that passing "-1" as the "time" value would give me a way to retain the useful "give the current date if no date passed" feature. Here's my html_select_date function call : {html_select_date prefix="payment_" time=$os.payment_date|default:-1} so if there hasn't been a payment_date, make sure we don't suggest one. Several changes are required in the function.html_select_date.php file : 1. Add $month_names[] = "..."; below $month_names = array(); 2. change 'values' => range(1, 12), to 'values' => range(0, 12), in the $month_result .= smarty_function_html_options call. 3. add array_unshift($days, ".."); below $days[$i] = sprintf($day_format, $days[$i]); 4. change 'values' => range(1, 31), to 'values' => range(0, 31), in the $day_result .= smarty_function_html_options call. 5. add $years_vals = $years; $years_show = $years; array_unshift($years_show, "...."); array_unshift($years_vals, "0"); below if ($reverse_years) { rsort($years, SORT_NUMERIC); } (for completeness should also deal with the "if ($year_as_text)" case too.) 6. change 'output' => $years, 'values' => $years, to 'output' => $years_show, 'values' => $years_vals, in the $year_result .= smarty_function_html_options call. This way, I get a nice collection of ".. ... ...." in my dropdowns, and no date data gets passed back by accident. Cheers, Gavin

« previous php.smarty.dev (#1053) next »