Zend - The PHP Company




Forms

Add Code


another date drop-down-menu  

Type: code fragment
Added by: wibi
Entered: 24/04/2001
Last modified: 04/12/2000
Rating: **** (11 votes)
Views: 26888
If you make form with birtdate-field or any other date-fields then this simple script may be can help.


<?
/********************************************************************
*    Date - form field function.
*    Its return a drop-down-menu form-field
*   Syntax :
*        - string listbox_date(string name, int selected-date);
*        - string listbox_month(string name, int selected-month);
*        - string listbox_year(string name, int start-year, int end-year, int selected-year);
*
*    Copyright (C) 2001 Wibisono Sastrodiwiryo. 
*       This program is free software licensed under the 
*       GNU General Public License (GPL).
*
*   CyberGL => Application Service Provider
*   http://www.cybergl.co.id
*    office@cybergl.co.id
*
*   $Id: date.php3,v 0.1 2001/04/24 21:6:31 wibi Exp $ 
*********************************************************************/

function listbox_date ($name$default=0) {
    
$result="<select name="$name" size=1>n";
    for (
$d=1;$d<=31;$d++) {
        if (
$default  == $d) {$selected="selected";} else {$selected="";}
        
$result.="<option value="$d$selected>$d</option>n";
    }
    
$result.="</select>n";
return 
$result;
}

function 
listbox_month ($name$default=0) {
    
$result="<select name="$name" size=1>n";
    for (
$m=1;$m<=12;$m++) {
        if (
$default  == $m) {$selected="selected";} else {$selected="";}
        
$result.="<option value="$m$selected>".date(Mmktime(0,0,0,$m,1,2000))."</option>n";
    }
    
$result.="</select>n";
return 
$result;
}

function 
listbox_year ($name$start$end$default=0) {
    
$result="<select name="$name" size=1>n";
    for (
$y=$end;$y>=$start;$y--) {
        if (
$default  == $y) {$selected="selected";} else {$selected="";}
        
$result.="<option value="$y$selected>$y</option>n";
    }
    
$result.="</select>n";
return 
$result;
}
?>


Usage Example


<?
require("date.php3");
?>
<form>
My Birth Date: 
<?echo listbox_date("tanggal"23);?> -
<?echo listbox_month("bulan"7);?> -
<?echo listbox_year("tahun"192019991973);?>
</form>


Rate This Script





Search



This Category All Categories