Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

更改用户注册生日时年份选择范围的方法

[复制链接]
szdxsw.com 发表于 2011-11-21 10:28:36 | 显示全部楼层 |阅读模式
最近 苏州宝宝网[www.insz.net]在网站实施过程中想把宝宝生日栏目中的“生日”范围更改一下,调用其程序的日期选择器,但郁闷的是,其中的年份范围是包含本年在内的前100年,比如今年2011年,范围是:2011~1912,这个范围有点大,也有点小瑕疵!
个人需求:
1、日期选择器需要年份范围是10年;
2、年份需要比本年预期一年,比如今年2011年,年份应该选择到2012;
在Discuz论坛中找了半天没找到,后来经过折腾解决了,方法如下:

打开 /source/function/function_profile.php 文件,找到函数 profile_setting($fieldid, $space=array(), $showstatus=false),要实现上述需求,依次做如下修改:
  1. 1:for ($i=0; $i<100; $i++),将其中的100修改为10;

  2. 2:$nowy = dgmdate($_G['timestamp'], 'Y'),在此后+1,即能达到2012年的效果!
复制代码
其它需求可查看注解即可!


  1. $html = '';
  2. if($fieldid == 'birthday') {
  3.   if($field['unchangeable'] && !empty($space[$fieldid])) {
  4.    return '<span>'.$space['birthyear'].'-'.$space['birthmonth'].'-'.$space['birthday'].'</span>';
  5.   }
  6.   $birthyeayhtml = '';
  7.   $nowy = dgmdate($_G['timestamp'], 'Y')+1;//其中的+1能达到范围比本年多一年
  8.   
  9.   //$i<100; 指的是年份包括今年在内的100年,如需要范围为10年,将100改为10即可!
  10.   for ($i=0; $i<100; $i++) {
  11.    $they = $nowy - $i;
  12.    $selectstr = $they == $space['birthyear']?' selected':'';
  13.    $birthyeayhtml .= "<option value="$they"$selectstr>$they</option>";
  14.   }
  15.   $birthmonthhtml = '';//月份
  16.   for ($i=1; $i<13; $i++) {
  17.    $selectstr = $i == $space['birthmonth']?' selected':'';
  18.    $birthmonthhtml .= "<option value="$i"$selectstr>$i</option>";
  19.   }
  20.   $birthdayhtml = '';//日期,对闰年判断
  21.   if(empty($space['birthmonth']) || in_array($space['birthmonth'], array(1, 3, 5, 7, 8, 10, 12))) {
  22.    $days = 31;
  23.   } elseif(in_array($space['birthmonth'], array(4, 6, 9, 11))) {
  24.    $days = 30;
  25.   } elseif($space['birthyear'] && (($space['birthyear'] % 400 == 0) || ($space['birthyear'] % 4 == 0 && $space['birthyear'] % 400 != 0))) {
  26.    $days = 29;
  27.   } else {
  28.    $days = 28;
  29.   }
  30.   for ($i=1; $i<=$days; $i++) {
  31.    $selectstr = $i == $space['birthday']?' selected':'';
  32.    $birthdayhtml .= "<option value="$i"$selectstr>$i</option>";
  33.   }
  34.   $html = '<select id="birthyear" name="birthyear" onchange="showbirthday();" tabindex="1">'
  35.     .'<option value="">'.lang('space', 'year').'</option>'
  36.     .$birthyeayhtml
  37.     .'</select>'
  38.     .'&nbsp;&nbsp;'
  39.     .'<select id="birthmonth" name="birthmonth" onchange="showbirthday();" tabindex="1">'
  40.     .'<option value="">'.lang('space', 'month').'</option>'
  41.     .$birthmonthhtml
  42.     .'</select>'
  43.     .'&nbsp;&nbsp;'
  44.     .'<select id="birthday" name="birthday" tabindex="1">'
  45.     .'<option value="">'.lang('space', 'day').'</option>'
  46.     .$birthdayhtml
  47.     .'</select>';
复制代码

快乐是因为分享,小技巧帮助需要的人,高手勿见笑,如有不明白的欢迎互相交流,邮箱: admin@insz.net
AD:苏州宝宝网[www.insz.net]诚换链接,正规网站即可。

64243354 发表于 2011-11-21 16:51:51 | 显示全部楼层
{:soso_e179:}挺好~支持一下~
回复

使用道具 举报

pcyi 发表于 2011-11-22 20:29:36 | 显示全部楼层
确实有点瑕疵  楼主很给力 哈哈
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-6-16 21:35 , Processed in 0.106548 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表