Support

  1. krnsgrffn
  2. Support
  3. Wednesday, July 08 2020, 08:17 PM
  4.  Subscribe via email
Hi-

I need to be able to show fields based on the age of a person filling out a registration form. I ask for their date of birth, and want to calculate their age based on that to set the value of a hidden field with their age and determine whether to show fields based on that value. I have found ways to calculate age both in javascript and PHP, but am uncertain which to use and where to use it in order to set the value for the hidden field.

Thanks.
admin Accepted Answer
Admin
Hi and sorry for late reply,
I'm not sure to understand well...anyway a simple solution is this:
- Override profile page: copy file from /components/com_jsn/views/profile/tmpl/default.php to /templates/your-theme-folder/html/com_jsn/profile/default.php
- In the new file, after line 24 add a code that calculate age and store the information in a hidden field:
$from = new DateTime($this->user->dob);
$to = new DateTime('today');
$this->user->age=$from->diff($to)->y;
$this->user->save();
NOTE: I assume "dob" is the alias of Date of Birth field and "age" is the alias of the hidden field

Now everytime the user show the profile then the hidden field that contain a age will be update, so you can assign conditions at the hidden field to show/hide other fields
  1. more than a month ago
  2. Support
  3. # 1
krnsgrffn Accepted Answer
Pro
Hi-
Thanks for the reply. No worries about the delay. This whole project has been on delay due to all the COVID19 weirdness. I am now finally getting back to this. If I am understanding this correctly, what you have given me is something that would happen when the user pulled up their profile after initial registration, not at the time of registration. I need the age field to be updated on change of the dob field BEFORE the initial save. It cannot wait until after the user has been created.

Maybe I will just resort to the awkwardness of the user filling out dob and age at the time of initial registration, and then using your idea after initial registration.

Thanks again.
  1. 3 weeks ago
  2. Support
  3. # 2
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Request Support

Support is currently Offline

Support Availability

Working days: Monday to Friday. The support staff is not available on weekends; in the most of cases tickets will not be answered during that time.

Reply time: Depending on the complexity of your support issue it's usually between a few minutes and 24 hours for paid members and about one week for free members. When we expect longer delays we will notify you.

Guidelines

Before you post: read the documentation and search the forums for an answer to your question.

When you post: include Site Details if you request a support (you can use the form below the reply in Site Details tab).

Auto Solved Question: If after a week the author of the post does not reply to a request by moderator, the question will be marked as resolved.

Language: only English

Search Users

Easy ProfileĀ® is not affiliated with or endorsed by Open Source Matters or the Joomla Project. Joomla is Free Software released under the GNU/GPL License.