Jump to content
giwrgos88

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

Share this post


Link to post
Share on other sites

Well.. 

Go to Localization > Pick the country you want to edit > Format Addresses

 

Is it this on a wrong post?

Share this post


Link to post
Share on other sites

Sorry didn't understood your question

You reply is for the age to make it required or you post it on a wrong section?

Share this post


Link to post
Share on other sites

I answer because you can set on there your required fields.

ok it looks like the birthday is required but on the form is not

 

Screen_Shot_2015_08_10_at_10_05_18.jpg

Share this post


Link to post
Share on other sites

ok it looks like the birthday is required but on the form is not

 

Screen_Shot_2015_08_10_at_10_05_18.jpg

 

But it's opnly for adresses... So i think it isn't that what you want... :/ 

Edited by Soulburst (see edit history)

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More