Jump to content

Birthday required in signup


Recommended Posts

I need to set up the birthday as a required field for new customers in prestashop 1.6.0.8. I tried some code from other posts like these ones: https://www.prestashop.com/forums/topic/436711-make-birthday-a-required-field/

or https://www.prestashop.com/forums/topic/276280-setting-required-fields-in-customer-registration/

 

What I have done until now is:

In authentication.tpl:

<div class="required form-group">
<label>{l s='Date of Birth'} <sup>*</sup></label>

This added the * in the label. But it seems that the “required" class doesn’t affect at all… I added the same in both places from this file. And also in these other files:

identity.tpl
order-opc-new-account.tpl


in classes/Customer.php:

'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate', 'required' => true),

With this the birthday is a required field, but even when the field is not empty it still says "there is an error, the birthday is required”. And the user can not sign up (attached a screenshot).

Any ideas about that? Everything will be welcome with a big hurrah!

post-79494-0-98562500-1433960331_thumb.png

Edited by isasimo (see edit history)
  • Like 1
Link to comment
Share on other sites

I already solved, thanks to this topic:
https://www.prestashop.com/forums/topic/390975-solucionado-poner-fecha-de-nacimiento-obligatoria/?hl=%2Bbirthday+%2Brequired&do=findComment&comment=1911097
 
What you need to add in controllers/AuthController.php this line:

$customer->birthday = (empty($_POST['years']) ? '' : (int)$_POST['years'].'-'.(int)$_POST['months'].'-'.(int)$_POST['days']);

// Preparing customer
$customer = new Customer();
$customer->birthday = (empty($_POST['years']) ? '' : (int)$_POST['years'].'-'.(int)$_POST['months'].'-'.(int)$_POST['days']);
$lastnameAddress = Tools::getValue('lastname');
$firstnameAddress = Tools::getValue('firstname'); 
$_POST['lastname'] = Tools::getValue('customer_lastname');
$_POST['firstname'] = Tools::getValue('customer_firstname');
$addresses_types = array('address');
Edited by isasimo (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 7 months later...

Thank you for posting this up! I was going crazy trying to link the two together and as it turns out it is the AuthController.php file addition under the controllers/front folder that did the trick. I am also adding in a minimum registered birthday of 18 years and older for other reasons. Any idea where the error message "birthday is invalid" when no birthday is selected or is under 18 years or older is located? I have gone through and made the changes for the birth year so it works but the error message is not correct. Thanks.

 

JDub

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...