1
jilong
how to auto insert age in profile?
  • 2007/8/10 6:47

  • jilong

  • Just popping in

  • Posts: 61

  • Since: 2007/1/10


I had modify a bit in edituser.php to let user to enter DOB and AGE. But for make sure get the correct age, can we make the field be auto fill in?

now i only able to make it show the error alert the age are not match.

in
if ($op == 'saveuser') {


i add this code:

$age '';        
if (!empty(
$_POST['age'])) {
$age $myts->stripSlashesGPC(trim($_POST['age']));
}
$birth explode("-"$dob);
$diff date("Y") - $birth[0];    
        
if (
$age == '' || $age != $diff) {
$errors[] = _US_NEEDAGE;
}


But if the age can be auto fill in will be excellent. Hope some one can help me out on this. Thanks

2
vaughan
Re: how to auto insert age in profile?
  • 2007/8/10 14:40

  • vaughan

  • Friend of XOOPS

  • Posts: 680

  • Since: 2005/11/26


i actually did this in my photo+profiles hack back in 2.0.10 days.

the hacks still available but is now defunct & unsupported since 2.0.13.2 because better methods came about.. such as smartprofile & formulize + reg codes etc.

but for your info you could probably disect the hack & use the script i made for displaying the users age instead of date of birth.

in include/functions.php

add this to the end >

// ----------- added by m0nty for profile fields hack ----------------
function CalcAge($date_of_birth) { // make sure it's YYYY-MM-DD
       
$cur_year=date("Y");
       
$cur_month=date("m");
       
$cur_day=date("d");            

       
$dob_year=substr($date_of_birth04);
       
$dob_month=substr($date_of_birth52);
       
$dob_day=substr($date_of_birth82);            
       
       if(
$cur_month>$dob_month || ($dob_month==$cur_month && $cur_day>=$dob_day) )
           return 
$cur_year-$dob_year;
       else
           return 
$cur_year-$dob_year-1;
   }    
// ----------- end of profile fields hack ----------------


remember to make sure the date submitted is in format YYYY-MM-DD

then to use the function.

in userinfo.php

you'll need your date of birth in the DB.

then simply use >

CalcAge($thisUser->getVar('user_birth'));


to translate the dob to an actual age.

if you need more help, let me know.. or if you wish to disect my profile hack you're welcome. just pm me your email and i'll send you the last 2.0.13.2 version

you'll see in the hack tho, i created and used a dobcalendar.js and used that on the edituser form etc to input the dob field instead of having users type it in.

Login

Who's Online

264 user(s) are online (198 user(s) are browsing Support Forums)


Members: 0


Guests: 264


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits