1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.4 Login page - Year field

Discussion in 'XenForo Questions and Support' started by flowerpot132, Sep 2, 2015.

  1. flowerpot132

    flowerpot132 Formerly mugtree

    Does it matter how the year is formatted when registering for xenforo? The year field seems to except anything right?
     
  2. Mike

    Mike XenForo Developer Staff Member

    I assume you mean 2 digits versus 4 and we do try to make a reasonable assumption as to what they mean, but it's still ambiguous.
     
  3. flowerpot132

    flowerpot132 Formerly mugtree

    I mean if you put in letters then it won't work right? Just numbers. But then it passes ok with just one number in. What are requirements of the field please? Can you put in 5 numbers?
     
  4. Mike

    Mike XenForo Developer Staff Member

    Non numbers will be treated as 0 (or "coerced" to an integer if possible). Otherwise, you need to enter something that could be a valid (in terms of reasonable) date of birth for someone would could reasonably be registering on the forum.
     
  5. flowerpot132

    flowerpot132 Formerly mugtree

    So are you saying by "reason" that me as the admin could interpret that as a year? Basically, what are the field requirements? Can i enter %£&"dfdf and it is still pass.
     
  6. Mike

    Mike XenForo Developer Staff Member

    For simplicity, let's just say it needs to be from 1900 to 2015 to be valid.
     
  7. flowerpot132

    flowerpot132 Formerly mugtree

    But it doesn't. I can put in 1 and the form still submits. Do you see what I mean?
     
  8. Mike

    Mike XenForo Developer Staff Member

    I covered that initially when I commented about 2 digit years (where 1 would be 01). Internally, here's the validation code:
    Code:
                    $year = $this->get('dob_year');
                    if (!$year)
                    {
                        $year = 2008; // pick a leap year to be sure
                    }
                    else if ($year < 100)
                    {
                        $year += ($year < 30 ? 2000 : 1900);
                        $this->set('dob_year', $year);
                    }
    
                    if ($year > intval(date('Y'))
                        || $year < 1900
                        || !checkdate($this->get('dob_month'), $this->get('dob_day'), $year)
                        || gmmktime(0, 0, 0, $this->get('dob_month'), $this->get('dob_day'), $year) > XenForo_Application::$time + 86400 // +1 day to be careful with TZs ahead of GMT
                    )
                    {
                        if ($this->_importMode)
                        {
                            // don't error, wipe it out
                            $this->set('dob_day', 0);
                            $this->set('dob_month', 0);
                            $this->set('dob_year', 0);
                        }
                        else
                        {
                            $this->error(new XenForo_Phrase('please_enter_valid_date_of_birth'), 'dob');
                        }
    
                        return false;
                    }
    
    
     
  9. flowerpot132

    flowerpot132 Formerly mugtree

    Ok so you can use one digit eg 1 and that equates to 01. You can use 2 digits and that equates correctly to 12. You can three digits, and that won't work. Four digits and that equates correctly to 1986. You can use 5 digits and that won't work. You can use text, that won't work.
     

Share This Page