1

When users register on my website, they have to fill in their name. However, not everyone wants his/her name to be displayed on his/her profile page. Therefore, I'd like to provide a checkbox "Show as anonymous" during the registration which changes the name to anonymous on the profile page. In other words, the checkbox rewrites the displayed name, as opposed to Is there a way to let every user can choose (e.g. on registration) whether their field is private or public?, where the field is hidden.

I rewrote the profile pages with user_view in the Pages section and I'm using Panels.

How can I do that?

1

1 Answer 1

1

You can add one more text field to user entity, keep it hidden.While registering the user check if show as anonymous user field is checked save the hidden field value as anonymous else copy the user name field to hidden field.

You can do the above changes in hook_user_presave().

Finally add this hidden field to your user view, instead of name field.

1
  • I created 2 rules (using drupal.stackexchange.com/questions/28750/…) instead of using the hook_user_presave(), but I'll accept your answer because you had the idea of adding a hidden field to the user account. Thanks!
    – Jeroen
    Nov 17, 2013 at 20:44

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.