3

How such inputs could be translated into DATE field in DB?

enter image description here

Customer insisted on such way to input user birthdate. First my thought was simply to concat in one field in beforeValidate, but after this inputs won't be able to display date, that was inputed, from the DB. How to avoid such restriction?

D.R.
  • 1,676
  • 2
  • 16
  • 37

1 Answers1

3
  1. Add these 3 fields as virtual properties in the model class.
  2. In beforeValidate() set the value of birthdate with combination of 3 virtual fields from the form.
  3. Add afterFind() in the model class where value of saved in DB birthdate property is used to set the values of 3 virtual properties.
  4. Now form properly holds 3 fields' values and combined date is saved in DB.
Bizley
  • 15,937
  • 5
  • 43
  • 53
  • Thank you for the answer. By "virtual fields" you mean adding fields to the "rules" array, but not creating a real field in the model class? In my case `[['birthdate_month', 'birthdate_day', 'birthdate_year'], 'string']` – D.R. Nov 25 '16 at 12:39
  • To the rules and to the model itself like `public $birthdate_month;` – Bizley Nov 25 '16 at 12:57