Smarty Internal Date function html_select_date () example Analysis _php instance

Source: Internet
Author: User
Tags php programming

This example describes the use of the Smarty internal date function html_select_date (). Share to everyone for your reference. Specifically as follows:

Main properties:

Prefix//string type default prefix named "Date_"
Start_year//string type defaults to the current year can still be expressed in (+/-n) mode as start_year= " -10" option is starting from 1998
End_year//string Type Default ditto available (+/-n) mode indicates that end_year= "+5" option is up to 2013
Field_order//string Type default mdy that is, the order of day of the month is released select
Month_format//string Type Default%b is displayed as January, February, etc.%b format Displays the first three letters of the month in shorthand form
%m format for numbers display month
Day_format//string Type Default%02d numeric representation from 01~31 and not associated with month%b format is rarely used in binary display formats

Additional properties:

Display_days//boolean Type Controls whether day's select is displayed
Display_months//boolean Type Controls whether the select of month is displayed
Display_years//boolean Type Controls whether the year's select is displayed
Year_as_text//boolean Type true display as text year false to Drop-down menu type
Reverse_years//boolean Type True the year is in reverse display
Year_size//string Type values are drop-down menu-type output 0 or 1 o'clock for the up and down arrows when greater than 1

Examples are as follows:

Copy Code code as follows:
{html_select_date prefix= "StartDate" time= $time start_year= "-5" end_year= "+1" Display_days=false}

OUTPUT: (current year is)

<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= "Ten" >October</option> <option value= "One" >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= " Selected>2000</option> <option value= "2001" >2001</option> </sElect>


Other properties, please debug yourself. The disadvantage of this date processing function is that day is not associated with month, and it is better to use JS processing

One of the functions that JS displays day can be defined as follows:

function Showdays (year,month) {
 var day= "Day";
 if (month.value==0) {
 document.getElementById (day). Length=1;
 } 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);
 } 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);
 } else{
 document.getElementById (day) length=1;
 CreateList (1,29,day);
 document.getElementById (day) length=1;
 CreateList (1,31,day);

I hope this article will help you with your PHP programming based on Smarty.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.