Bert Jans Posted April 13, 2015 Share Posted April 13, 2015 Hi, I'm using 1.6.0.11 and I want to make the field "Birthday" mandatory when I create an new account. I made some changes in: Classes/Customer.php: 'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate', 'required' => true), and in: themes/authentication.tpl: {$HOOK_CREATE_ACCOUNT_TOP} ‘Date of Birth’. <div class = “required form-group”> and added an * … s=’Date of Birth’} <sup>*</sup></label> So, by creation the asterisk is there and the inputs are required. BUT if I want to save the account it results in: "1 error - Birthday is required" even when I filled in the fields and saves nothing. What have I forgotten? Link to comment Share on other sites More sharing options...
bellini13 Posted April 13, 2015 Share Posted April 13, 2015 I don't think this approach will work for date of birth. While in the Customer class, the date of birth is a single date field called 'birthday', that is not true for the html form fields that you are submitting. The html form fields for date of birth are actually 3 different fields (month, day and year). And when you submit the form, the authcontroller attempts to validate that all the required fields are submitted BEFORE merging the month, day and year into a single field called 'birthday' and setting the value in the Customer object. Since the customer object does not have the 'birthday' variable established until AFTER, setting required == true will cause it to fail the validation. This means you will need to edit or override the AuthController so that the birthday is set BEFORE the validation occurs, something like this... $customer->birthday = (empty($_POST['years']) ? '' : (int)Tools::getValue('years').'-'.(int)Tools::getValue('months').'-'.(int)Tools::getValue('days')); if (!Validate::isBirthDate($customer->birthday)) $this->errors[] = Tools::displayError('Invalid date of birth.'); $this->errors = array_unique(array_merge($this->errors, $customer->validateController())); Link to comment Share on other sites More sharing options...
Bert Jans Posted April 13, 2015 Author Share Posted April 13, 2015 (edited) Thank you for your but input. Since I am a newbie , can you let me now where I can find the syntax I need to change? Do I still need to keep the changes I allready made? Thank you so much. Edited April 13, 2015 by Bert Jans (see edit history) Link to comment Share on other sites More sharing options...
isasimo Posted June 10, 2015 Share Posted June 10, 2015 (edited) Did you already figure it out anything? I have tried the code recommended for bellini13 but it's not working for my site neither. I did the changes in controllers/front/AuthController.php is it correct? I did exactly the same as Bert Jans did but I still have the error message. Edited June 10, 2015 by isasimo (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts