This article describes the usage of smarty internal date function html_select_date() with examples. Share it with everyone for your reference. The details are as follows:
Main attributes:
prefix //string type The default prefix is "Date_"
start_year //string type defaults to the current year and can still be expressed in (/-N) mode. For example, start_year="-10" option starts from 1998
end_year //string type defaults to the same as above and can be expressed in (/-N) mode. For example, end_year=" 5" option will end in 2013
field_order //string type Default MDY is arranged in the order of month, day and year select
month_format //String type Default %B means January, February, etc. The %b format is an abbreviation and displays the first three letters of the month
//%m format is a digital display month
day_format //string type default d number represents from 01 to 31 and is not associated with the month %b format is binary display format rarely used
Other attributes:
display_days //boolean type controls whether the day selection is displayed
display_months //boolean type controls whether the month selection is displayed
display_years //boolean type controls whether the year selection is displayed
year_as_text //boolean type true is displayed as text type year false is displayed as drop-down menu type
reverse_years //boolean type, if true, the years are displayed in reverse order
Year_size // The string type value is controlled by the drop -down dish output 0 or 1 when the value is greater than 1 is controlled by the upper and lower arrows
month_size //Same as above
day_size //Same as above
An example is as follows:
Copy code The code is as follows: {html_select_date prefix="StartDate" time=$time start_year="-5" end_year=" 1" display_days=false}
OUTPUT: (current year is 2000)
<select name="StartDateMonth"> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12" selected>December</option> </select> <select name="StartDateYear"> <option value="1999">1995</option> <option value="1999">1996</option> <option value="1999">1997</option> <option value="1999">1998</option> <option value="1999">1999</option> <option value="2000" selected>2000</option> <option value="2001">2001</option> </select>
Please debug other attributes by yourself. The disadvantage of this date processing function is that day and month are not related. It is better to use js to process
The function that displays day in js can be defined as follows:
function showdays(year,month){ var day="day"; if(month.value==0){ document.getElementById(day).length=1; return; }else{ if(month.value==1||month.value==3||month.value==5||month.value==7||month.value==8||month.value==10||month.value==12){ document.getElementById(day).length=1; createlist(1,32,day); return; }else if(month.value==2){ if(year.value%4==0&&year.value%100!=0||year.value%400==0){ document.getElementById(day).length=1; createlist(1,30,day); return; }else{ document.getElementById(day).length=1; createlist(1,29,day); return; } }else{ document.getElementById(day).length=1; createlist(1,31,day); return; } } }
I hope this article will be helpful to everyone’s smarty-based PHP programming design.