Jump to content

Edit History

kyaj323

kyaj323

Hi All,

I am using version 1.7.8.6

I changed classes/form/CustomerFormatter.php line 212 set required true to require birthday.

        if ($this->ask_for_birthdate) {
            $format['birthday'] = (new FormField())
                ->setName('birthday')
                ->setType('text')
                ->setLabel(
                    $this->translator->trans(
                        'Birthdate',
                        [],
                        'Shop.Forms.Labels'
                    )
                )
                ->setRequired(true)
                ->addAvailableValue('placeholder', Tools::getDateFormat())

 

1. should i create a new CustomerFormatter.php and put it in the override/classes/form instead of modifying the root/classes/form/?

 

2.  I added the below code, however, if the age is younger than 18 it says "format should be 05/31/1970." If its 18 and older user can proceed.

How can i change the message to show you must be 18 years or older to proceed?

3. I like to add another condition if greater than 18 but younger than 60.

 

<?php
//User age verification 18 years and older
class Validate extends ValidateCore
{

public static function isBirthDate($date, $format = 'Y-m-d')
    {
        if (empty($date) || $date == '0000-00-00') {
            return true;
        }

        $d = DateTime::createFromFormat($format, $date);
        if (!empty(DateTime::getLastErrors()['warning_count']) || false === $d) {
            return false;
        }
        
        $d->add(new DateInterval("P18Y"));
        return $d->setTime(0, 0, 0)->getTimestamp() <= time();
    }
}

 

Thanks

-K

kyaj323

kyaj323

Hi All,

I am using version 1.7.8.6

I changed classes/form/CustomerFormatter.php line 212 set required true to require birthday.

        if ($this->ask_for_birthdate) {
            $format['birthday'] = (new FormField())
                ->setName('birthday')
                ->setType('text')
                ->setLabel(
                    $this->translator->trans(
                        'Birthdate',
                        [],
                        'Shop.Forms.Labels'
                    )
                )
                ->setRequired(true)
                ->addAvailableValue('placeholder', Tools::getDateFormat())

 

1. should i create a new CustomerFormatter.php and put it in the override/classes/form instead of modifying the root/classes/form/?

 

2.  I added the below code, however, if the age is younger than 18 it says "format should be 05/31/1970." If its 18 and older user can proceed.

How can i change the message to show you must be 18 years or older to proceed?

 

<?php
//User age verification 18 years and older
class Validate extends ValidateCore
{

public static function isBirthDate($date, $format = 'Y-m-d')
    {
        if (empty($date) || $date == '0000-00-00') {
            return true;
        }

        $d = DateTime::createFromFormat($format, $date);
        if (!empty(DateTime::getLastErrors()['warning_count']) || false === $d) {
            return false;
        }
        
        $d->add(new DateInterval("P18Y"));
        return $d->setTime(0, 0, 0)->getTimestamp() <= time();
    }
}

 

Thanks

-K

kyaj323

kyaj323

Hi All,

I am using version 1.7.8.6

I changed classes/form/CustomerFormatter.php line 212 set required true to require birthday.

        if ($this->ask_for_birthdate) {
            $format['birthday'] = (new FormField())
                ->setName('birthday')
                ->setType('text')
                ->setLabel(
                    $this->translator->trans(
                        'Birthdate',
                        [],
                        'Shop.Forms.Labels'
                    )
                )
                ->setRequired(true)
                ->addAvailableValue('placeholder', Tools::getDateFormat())

 

1. should i create a new CustomerFormatter.php and put it in the override/classes/form instead of modifying the root/classes/form/?

 

2.  I added the below code, however, if the age is younger than 18 it says "format should be 05/31/1970." If its 18 and older user can proceed.

How can i change the message to show you must be 18 years or older to proceed?

 

 

On 4/30/2020 at 9:31 AM, ByteEmotions said:

See my last post for override the birthday field.

For the age check of 18 years I have override the Validate.php. Create override/classes/Validate.php

<?php

// User has to have a minimum age of 18 years

class Validate extends ValidateCore
{

 public static function isBirthDate($date, $format = 'Y-m-d')
    {
        if (empty($date) || $date == '0000-00-00') {
            return false;
        }

        $d = DateTime::createFromFormat($format, $date);
        if (!empty(DateTime::getLastErrors()['warning_count']) || false === $d) {
            return false;
        }
        
        //adding 18 years to the birth date
        $d->add(new DateInterval("P18Y"));

        return $d->getTimestamp() < time();
    }
}

After that change the text of the error message (field validation) to something like: "Format has to be: 1970/20/04 (minimum age is 18 years)"

 

Thanks

-K

kyaj323

kyaj323

Hi All,

I am using version 1.7.8.6

I changed classes/form/CustomerFormatter.php line 212 set required true to require birthday.

        if ($this->ask_for_birthdate) {
            $format['birthday'] = (new FormField())
                ->setName('birthday')
                ->setType('text')
                ->setLabel(
                    $this->translator->trans(
                        'Birthdate',
                        [],
                        'Shop.Forms.Labels'
                    )
                )
                ->setRequired(true)
                ->addAvailableValue('placeholder', Tools::getDateFormat())

 

1. should i create a new CustomerFormatter.php and put it in the override/classes/form instead of modifying the root/classes/form/?

 

2.  I added the below code, however, it is not checking minimum age. I can put year 2020 and it will still let me proceed.

Any ideas?

On 4/30/2020 at 9:31 AM, ByteEmotions said:

See my last post for override the birthday field.

For the age check of 18 years I have override the Validate.php. Create override/classes/Validate.php

<?php

// User has to have a minimum age of 18 years

class Validate extends ValidateCore
{

 public static function isBirthDate($date, $format = 'Y-m-d')
    {
        if (empty($date) || $date == '0000-00-00') {
            return false;
        }

        $d = DateTime::createFromFormat($format, $date);
        if (!empty(DateTime::getLastErrors()['warning_count']) || false === $d) {
            return false;
        }
        
        //adding 18 years to the birth date
        $d->add(new DateInterval("P18Y"));

        return $d->getTimestamp() < time();
    }
}

After that change the text of the error message (field validation) to something like: "Format has to be: 1970/20/04 (minimum age is 18 years)"

 

Thanks

-K

×
×
  • Create New...