Jump to content

How to make birthday field required on registration


Recommended Posts

Hello, I'm looking a method to make birthday field on the registration form required because I want to add some warnings to categories which needs age restrictions.

 

I don't want on the next update of prestashop this modification to be lost.

 

I'm working on 1.6.1.0

 

Thank you

Link to comment
Share on other sites

  • 1 year later...

Hello, 

 

You can do this by doing two overrides.

 

The first one is the Customer.php. We have to set the birthday field to require true.

<?php

//overrides/classes/Customer.php
// Set the birthday to required true

class Customer extends CustomerCore
{

    public function __construct($id = null)
    {
        self::$definition['fields']['birthday'] = array(
            'type' => self::TYPE_DATE,
            'validate' => 'isBirthDate',
            'required' => true
        );
        parent::__construct($id);
    }
}

The second is the front controller AuthController.php, if you don't do this one, you will never be able to create an account. Prestashop check if the required fields are in the POST, the birthday is calculated after so he won't be there at the control. So we had it before the control.

<?php

// overrides/controllers/front/AuthController.php
// Add the birthday to the POST to handle valideController

class AuthController extends AuthControllerCore
{
    protected function processSubmitAccount()
    {
        $birthday = (empty($_POST['years']) ? '' : (int)Tools::getValue('years').'-'.(int)Tools::getValue('months').'-'.(int)Tools::getValue('days'));
        if ($birthday) {
            $GLOBALS['_POST']['birthday'] = $birthday;
        }

        return parent::processSubmitAccount();
    }
}

And don't forget to delete the file in cache/class_index.php (it will be generated automatically), otherwise, those files won't be loaded by Prestashop.

Edited by jsanchez67 (see edit history)
Link to comment
Share on other sites

  • 11 months later...
  • 11 months later...
On 17.8.2016 at 11:20 AM, jsanchez67 said:

Hello, 

 

You can do this by doing two overrides.

 

The first one is the Customer.php. We have to set the birthday field to require true.


<?php

//overrides/classes/Customer.php
// Set the birthday to required true

class Customer extends CustomerCore
{

    public function __construct($id = null)
    {
        self::$definition['fields']['birthday'] = array(
            'type' => self::TYPE_DATE,
            'validate' => 'isBirthDate',
            'required' => true
        );
        parent::__construct($id);
    }
}

The second is the front controller AuthController.php, if you don't do this one, you will never be able to create an account. Prestashop check if the required fields are in the POST, the birthday is calculated after so he won't be there at the control. So we had it before the control.


<?php

// overrides/controllers/front/AuthController.php
// Add the birthday to the POST to handle valideController

class AuthController extends AuthControllerCore
{
    protected function processSubmitAccount()
    {
        $birthday = (empty($_POST['years']) ? '' : (int)Tools::getValue('years').'-'.(int)Tools::getValue('months').'-'.(int)Tools::getValue('days'));
        if ($birthday) {
            $GLOBALS['_POST']['birthday'] = $birthday;
        }

        return parent::processSubmitAccount();
    }
}

And don't forget to delete the file in cache/class_index.php (it will be generated automatically), otherwise, those files won't be loaded by Prestashop.

 

Could someone please explain to me where to insert this code in PS1.7.4.1 please?

when i go to .../override/classes there are only a bunch of folders which all only have "index.php" files in them but i can not find the customer.php or authcontroller.

 

thank you for helping a noob getting better :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...