On my site, users input their birthday, from which I use a computed field to calculate their age. Then, based on that age, I use rules to add a taxonomy term to their profile to classify them into one of the following age groups:

  • 20s
  • 30s
  • 40s
  • 50s
  • 60s
  • 70+

I have a view that allows members to search other members' profiles, and on this view I have an exposed filter for the taxonomy vocabulary age group. The exposed filter widget is converted from a dropdown box to a list of checkboxes using the Better Exposed Filters module.

What I want to do

This works well, but I want to further improve the UX by automatically checking boxes based on the user's age when he or she visits the page. Ideally, I want to automatically check the box for the user's own age group (e.g., a user in his/her 20s will automatically have the 20s box checked, while a user in his/her 40s will have the 40s box checked).

What I tried

I have no way how to implement this smartly. One possibility that entered my mind is creating a panel with variants for each age group and then cloning a view once per age group and then using views rewriting functionality to rewrite the query strings for all of the views to check the appropriate boxes... but this would lead to a huge amount of duplication and be very difficult to maintain.

1 Answer 1


As a huge fan of direct approach and writing own helper modules, I would make it happen mostly with jQuery.

  1. Outputting user's age or age category in a hidden <div> is easy. You can append it to view's form with hook_form_alter, or simply output it as a block that will never really be seen.
  2. Attach your JS library to views form (or again - simply load it and make it see if form is on page)
  3. In behavior, read user's age from <div> created in 1. and based on that check checkboxes. Invoke click() on them for full emulation of user interaction (i.e. to reload what would get reloaded if it was user who selected it).
  • I believe there should be some smart way to connect current user's taxonomy with views taxonomy, but I cannot find it.
    – Mołot
    Oct 11, 2013 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.