Welcome Guest, Not a member yet? Register   Sign In
Custom Validate Birthday with value for each $year, $month, $day
#4

(This post was last modified: 06-29-2022, 08:42 AM by AgBRAT.)

I solved it thank you for the help! 

This is what I ended up doing with my custom rule:
PHP Code:
public function validateDate($strstring $fields, array $data)
    {
        if (checkdate((int) $data['bday_month'], (int) $data['bday_day'], (int) $data['bday_year'])) {
        
            
return TRUE;
    
        
} else {

            return FALSE;
        }

    

And here is my controller:
PHP Code:
$bday_year $this->request->getPost('bday_year');
            $bday_month $this->request->getPost('bday_month');
            $bday_day $this->request->getPost('bday_day');

            $validation->getRuleGroup('date');
            $validation->setRuleGroup('date');
            $validation->run(['bday_month' => $bday_month'bday_day' => $bday_day'bday_year' => $bday_year], 'date'); 

(06-29-2022, 08:34 AM)AgBRAT Wrote: I solved it thank you for the help! 

This is what I ended up doing with my custom rule:
PHP Code:
public function validateDate($strstring $fields, array $data)
    {
        if (checkdate((int) $data['bday_month'], (int) $data['bday_day'], (int) $data['bday_year'])) {
        
            
return TRUE;
    
        
} else {

            return FALSE;
        }

    

And here is my controller:
PHP Code:
$bday_year $this->request->getPost('bday_year');
            $bday_month $this->request->getPost('bday_month');
            $bday_day $this->request->getPost('bday_day');

            $validation->getRuleGroup('date');
            $validation->setRuleGroup('date');
            $validation->run(['bday_month' => $bday_month'bday_day' => $bday_day'bday_year' => $bday_year], 'date'); 
I also format the date time for use in my views with an entity:

PHP Code:
public function setAge(string $profile)
    {
        $db = \Config\Database::connect();
        $this->builder $db->table('users');

        $user $this->userModel->getUser($profile);

        $month $user->bday_month;
        $day $user->bday_day;
        $year $user->bday_year;

        $bday Time::create($year$month$day);

        $this->attributes['age'] = $bday->toDateTimeString();

    }

public function 
getAge(string $format 'words')
    {
        if ($format === 'words' && $this->attributes['age'] !== NULL) {

            return $this->attributes['age'] = get_date_words($this->attributes['age']);
        
        
} elseif ($format === 'none' && $this->attributes['birthday'] !== NULL) {

            return $this->attributes['age'];
        }
    
Reply


Messages In This Thread
RE: Custom Validate Birthday with value for each $year, $month, $day - by AgBRAT - 06-29-2022, 08:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB