mr_absinthe Posted August 17, 2017 Share Posted August 17, 2017 Does anybody know how to make birthday field in registration form required (not optional) in v 1.7.2? There is no such option in settings and none of those guides I found work in this version. Link to comment Share on other sites More sharing options...
mr_absinthe Posted August 23, 2017 Author Share Posted August 23, 2017 Nobody...? I'm sure that someone had the same request... Link to comment Share on other sites More sharing options...
prestahero.com Posted August 24, 2017 Share Posted August 24, 2017 hi Open this file classes/form/CustomerFormatter.php In Prestashop 1.7.2.0, line 193 just add "->setRequired(true)" as the following screenshot: http://prntscr.com/gcdtvm On other Prestashop 1.7.x version the line may be different but you just find the birthday field and set it required as my screenshot above If you want to keep the changes for future updates, you should override the class instead of making direct changes as my guide Good luck Trong 7 Link to comment Share on other sites More sharing options...
prestahero.com Posted August 24, 2017 Share Posted August 24, 2017 Frontend when birthday field is required: http://prntscr.com/gcduyw Link to comment Share on other sites More sharing options...
mr_absinthe Posted August 24, 2017 Author Share Posted August 24, 2017 Works as expected! Thank you! Would you be so kind as to share the class override please? I have also removed mr & mrs from the same file thus it would be nice to have that all in one override file. Link to comment Share on other sites More sharing options...
prestahero.com Posted August 24, 2017 Share Posted August 24, 2017 On 8/24/2017 at 8:35 AM, mr_absinthe said: Works as expected! Thank you! Would you be so kind as to share the class override please? I have also removed mr & mrs from the same file thus it would be nice to have that all in one override file. you're welcome. what is your Prestashop version? I'll help make an override file and send it to you Link to comment Share on other sites More sharing options...
mr_absinthe Posted August 24, 2017 Author Share Posted August 24, 2017 Thank you very much, I have v 1.7.2. Do you think it's possible to include the removal of mr & mrs in that file as well? I have edited two files as advised here: https://www.prestashop.com/forums/topic/623679-help-to-remove-social-title-mr-mrs-in-v172/?p=2596119 Link to comment Share on other sites More sharing options...
prestahero.com Posted August 25, 2017 Share Posted August 25, 2017 On 8/24/2017 at 10:54 AM, mr_absinthe said: Thank you very much, I have v 1.7.2. Do you think it's possible to include the removal of mr & mrs in that file as well? I have edited two files as advised here: https://www.prestashop.com/forums/topic/623679-help-to-remove-social-title-mr-mrs-in-v172/?p=2596119 I just tried to make an override file but seems Prestashop 1.7 have problem, it ignore the override. so just keep the changes in your core files Link to comment Share on other sites More sharing options...
selectshop.at Posted August 25, 2017 Share Posted August 25, 2017 On 8/25/2017 at 2:19 AM, ets-soft said: I just tried to make an override file but seems Prestashop 1.7 have problem, it ignore the override. so just keep the changes in your core files That's the reason why experienced developers are suggesting TO DON'T USE Prestashop 1.7. IN PRODUCTION. It is still in development, full of bugs and also a version without any coding standard, cause it is half smarty half symfony and both not compatible together. PS 1.7. is for developers to play and learn, but not a version for sellers. Best is to sort it out and wait for next major version, which should be 100% symfony framework instead of a hybrid non-working version. Link to comment Share on other sites More sharing options...
mr_absinthe Posted August 25, 2017 Author Share Posted August 25, 2017 On 8/25/2017 at 2:19 AM, ets-soft said: I just tried to make an override file but seems Prestashop 1.7 have problem, it ignore the override. so just keep the changes in your core files Thank you anyway for trying. On 8/25/2017 at 6:13 AM, selectshop.at said: That's the reason why experienced developers are suggesting TO DON'T USE Prestashop 1.7. IN PRODUCTION. It is still in development, full of bugs and also a version without any coding standard, cause it is half smarty half symfony and both not compatible together. PS 1.7. is for developers to play and learn, but not a version for sellers. Best is to sort it out and wait for next major version, which should be 100% symfony framework instead of a hybrid non-working version. And that will be what version in your opinion? And what else could be used? Older version...? Link to comment Share on other sites More sharing options...
selectshop.at Posted August 25, 2017 Share Posted August 25, 2017 On 8/25/2017 at 7:27 PM, mr_absinthe said: And that will be what version in your opinion? And what else could be used? Older version...? PS 1.6. latest. Link to comment Share on other sites More sharing options...
backamblock Posted July 22, 2018 Share Posted July 22, 2018 On 8/24/2017 at 7:11 AM, ets-soft said: ... file classes/form/CustomerFormatter.php ...line 193 just add "->setRequired(true)" as the following screenshot: http://prntscr.com/gcdtvm ... Expand Thank you for this fast and easy solution! for the updates an override would be cool. i have prestashop 1.7.4.1 at the moment. i have read the documentation for the overrides but i can't understand it I know i have to write the new code that replaces the old code, but how do i define exactly what code is to be replaced? and one thing that would be really cool: is it possible to define in that override that prestashop checks the age of the customer on registration? so only over 18 can register? Link to comment Share on other sites More sharing options...
ican Posted July 26, 2018 Share Posted July 26, 2018 On 8/17/2017 at 9:15 AM, mr_absinthe said: Does anybody know how to make birthday field in registration form required (not optional) in v 1.7.2? There is no such option in settings and none of those guides I found work in this version. Expand Please find the answer in below post. I commented for mobile number required. You can follow same for birth date also. https://www.prestashop.com/forums/topic/867885-how-to-make-mobile-number-mandatory-prestashop-17/ Link to comment Share on other sites More sharing options...
Puppo Posted March 30, 2020 Share Posted March 30, 2020 Works perfect! Thank you. I someone can show how to make a override with this fix it would be great! Link to comment Share on other sites More sharing options...
ByteEmotions Posted April 30, 2020 Share Posted April 30, 2020 (edited) On 3/30/2020 at 11:59 AM, Puppo said: Works perfect! Thank you. I someone can show how to make a override with this fix it would be great! Expand Create override/classes/form/CustomerFormatter.php <?php use Symfony\Component\Translation\TranslatorInterface; class CustomerFormatter extends CustomerFormatterCore { private $translator; private $language; //translator and language are private in parent class, override need public function __construct( TranslatorInterface $translator, Language $language ) { $this->translator = $translator; $this->language = $language; parent::__construct($translator,$language); } public function getFormat() { $format = parent::getFormat(); //override/add all customisations for fields $format['birthday'] = (new FormField()) ->setName('birthday') ->setType('text') ->setLabel( $this->translator->trans( 'Birthdate', [], 'Shop.Forms.Labels' ) ) ->addAvailableValue('placeholder', Tools::getDateFormat()) ->addAvailableValue( 'comment', $this->translator->trans('(E.g.: %date_format%)', array('%date_format%' => Tools::formatDateStr('31 May 1970')), 'Shop.Forms.Help') ) ->setRequired(true); //As addConstraints method is private we need to call the logic here. We don't need to iterate over all the fields again, just the changed ones. $constraints = Customer::$definition['fields']; $field = $format['birthday']; if (!empty($constraints[$field->getName()]['validate'])) { $field->addConstraint( $constraints[$field->getName()]['validate'] ); } return $format; } } If you need a value check like $ask_for_birthdate just override it like the __construct method: private $ask_for_birthdate = true; public function setAskForBirthdate($ask_for_birthdate) { $this->ask_for_birthdate = $ask_for_birthdate; return parent::setAskForBirthdate($ask_for_birthdate); } Edited April 30, 2020 by ByteEmotions code format (see edit history) 1 Link to comment Share on other sites More sharing options...
ByteEmotions Posted April 30, 2020 Share Posted April 30, 2020 On 7/22/2018 at 2:34 PM, backamblock said: Thank you for this fast and easy solution! for the updates an override would be cool. i have prestashop 1.7.4.1 at the moment. i have read the documentation for the overrides but i can't understand it I know i have to write the new code that replaces the old code, but how do i define exactly what code is to be replaced? and one thing that would be really cool: is it possible to define in that override that prestashop checks the age of the customer on registration? so only over 18 can register? Expand 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)" 2 Link to comment Share on other sites More sharing options...
Puppo Posted May 1, 2020 Share Posted May 1, 2020 @ByteEmotions Thank you, will try that out and report how it works for me. 1 Link to comment Share on other sites More sharing options...
ByteEmotions Posted June 1, 2020 Share Posted June 1, 2020 On 5/1/2020 at 12:46 PM, Puppo said: @ByteEmotions Thank you, will try that out and report how it works for me. Expand Hi @Puppo, just curious if it works for you? Link to comment Share on other sites More sharing options...
Puppo Posted June 1, 2020 Share Posted June 1, 2020 Dear @ByteEmotions I had a lot of trouble with my site in the last few weeks so I moved this task backwards. Thx for the reminder. I will come back for shure because we need this function and I don't like to lose it after each update. Link to comment Share on other sites More sharing options...
kyaj323 Posted June 17, 2022 Share Posted June 17, 2022 (edited) 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 Edited June 19, 2022 by kyaj323 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now