Managing account registration for multiple user types

The Scenario

You're building a new Drupal site that needs to handle two distinct types of users: Consumers and Service Providers. Each user group must have a unique role, profile type, and registration page. Users of each type should be able to visit your site, find the correct registration page, fill out their profile, and be granted an account with the correct role. Sounds easy, right?

Well, I recently found myself in this exact scenario. I was surprised to find that no combination of modules would exactly fit these requirements. This seemed like a great opportunity to build a legitimate, contributed module. Here it is: Profile2 Registration Path.

The purpose of this blog post is to tell a bit of that story, but more importantly, to show you how to do use it!

The Journey

Jump to the Quick Step-by-step (TLDR)

Drupal 7 core provides us with an easy means of adding fields to the user entity. Unfortunately, using the core method requires that we make said fields available to all users. That's not very useful for our current requirements. Enter Profile2.

Designed to be the successor of the core profile module, Profile2 gives us a great starting point. Let's take a quick snippet from the Profile2 project description:

  • With profile2 user account settings and user profiles are conceptually different things, e.g. with the "Profile pages" module enabled users get two separate menu links "My account" and "My profile".
  • Profile2 allows for creating multiple profile types, which may be assigned to roles via permissions (e.g. a general profile + a customer profile)
  • Profile2 supports private profile fields, which are only shown to the user owning the profile and to administrators.

Awesome. Now we can create a Consumer profile type and a Service Provider profile type. We're all set, right? Not quite. We need to make sure that our users can easily fill out these profiles during registration, and that they are granted the correct user roles after signing up.

The Problem with Profile2

By default, the Profile 2 module permits you to add fields from each profile type to the default user registration form. Unfortunately, there is only one user registration form. Thus, during registration, every user will be presented with fields from all of the selected profiles. If you have two profile types targeted at two different audiences, you cannot have two separate registration forms. Bummer.

The Solution

Profile2 Registration Path enables you to set a unique registration path for each Profile2 profile type. Users who register via that unique path will be presented with fields from the specified profile type(s), and may have corresponding roles assigned to them upon account creation. Yay.

Here's a quick list of features taken from the Profile2 Registration Path project page:

  • Each registration path can be assigned roles that will be granted to users upon registration
  • Multiple profile types can be assigned to a shared registration path.
  • Profile types can be attached to the core 'user/register' page (while still maintaining other, unique registration paths).

So now that we have all of the tools that we need, how do we put it all together?

The Quick Step-by-step (TLDR)

  1. Download Profile2
  2. Download Profile2 Registration Path
  3. Enable the modules
  4. Create the 'consumer' and 'service provider' roles
  5. Go to admin/structure/profiles and add a new profile type named 'consumer'
  6. Check 'Enable unique registration path'
  7. Enter a URL path to use for this profile type, e.g., 'consumer/register'
  8. Select the role(s) that you would like to apply to users registering from this path. In this case, 'consumer'
  9. Add a few fields to the profile type
  10. Create additional profile types as needed
  11. Configure your permissions so that the correct roles can edit the correct profile types. E.g., only users with role 'consumer' can edit profiles of type 'consumer'

That should do it! You now have a site that can truly support the organic growth of multiple, distinct user groups.

After-thoughts

I initially tried to collaborate with the maintainers of the Auto Assign Role module, which was my go-to Drupal 6 solution for this scenario. I submitted a patch here that would introduce a hook, which would in turn permit the integration of other modules with AAR. Unfortunately, nothing came of it. I still think this is a good idea, so feel free to petition for it!

I'm working on adding more features to Profile2 Registration Path, including:

  • Unique registration blocks
  • Per-profile page titles for the login, registration, and forgot password pages (implemented in dev)

Of course, all feature requests and code contributions are welcome!

Happy coding.

Drupal Version Compatibility: 

Comments

Great looking module and great timing, need something like this for a project. Thanks!

Great post I looking some like this.

Thanks a lot.

This is awesome, good work. This is a fairly common use case scenario that now has a great module for D7.

I am going to create an ecommerce site where there will be clients and vendors...will it work with Drupal commerce too?

Is there are way for the path2registration path to be viewable upon normal login. I dont want to show this registration page to anonymous users, because I have a custom jobs module, where a I wish for the job applicant to first create username and email account with email verification, taking them to the path2registration page after auto login.

I hope this makes any sense!

If I understand you correctly, you're asking if you can prompt the user to fill in profile fields after registration. If this is what you'd like to do, I'd suggest simply using the Rules module to redirect users to the 'edit profile' page after logging in for the first time.

i didnt try your cocktail yet, but im thrilled with it and hope it goes well.

Thanks

Hi, I am pretty new to all this and having some trouble with unique registrations I am trying to create.
Any unique profile registration I create has a duplicate of username, email and password fields. What I mean is that people who register on my site use the Drupal core registration process for general and pesonal details. Then they have the option of completing a seperate registration for a more specific profile type like childminder or nanny or babysitter. But they are once again faced with fields for inputting username, email and password. I am likely doing something wrong as opposed to this being a flaw. Any ideas?

I did everything, but i created two equal text lists in both (client and provider) registration forms. Then I attempted to build a view that allows the client look for a concrete type of provider, but the data chosen by each user (client or provider) is not available in views.
In detail: each user must pick an instrument. The provider and the client both chose the same instrument (guitar) Later I want to let the client look for a user, of the type 'provider' and that chose 'guitar' on its registration. But the 'instrument' field is not available in views.

Anyone can point me in the right direction?

thanks

Just wanted to say thanks. I've spent all morning looking for an alternative to Auto Assign Role, having used D6 up until now. My searches came up with Profile2 a lot but not your module. I'm about to post a couple of replies to help others looking for something like this.

Thanks for your awesome contribution... I am still learning drupal and was getting very frustrated with the profile related questions I had... your blog breaks a month-long jinx for me... I am not a developer but will be very pleased to help you with anything that I could contribute. Thanks much.

Great post , thanks a lot.

On a conference website, we have diff roles, visitor, volunteer, keynote speaker, session speaker, minor sponsor, major sponsor, organizer and a hired worker... with each having access to diff content types on the website... what if a visitor registers as a visitor and then wants to become a sponsor (visitor->sponsor) or other scenarios such as (session speaker->keynote speaker) and then having to fill in the fields in the other role also... will the user have to repeat the entire registration process again... or could there be a method where only the additional fields are presented to register as another role in addition to the previous role... any help/ guidance is appreciated... thanks...

What if engagement of the registered users on my site graduates and it is necessary to fill out only some differentiall fields. There is still also need to apply multiple registration forms for already (in the moment of registration) differed user roles (depended on their actuall engagement) which will share some basic fields (for example First ad Last Name, Birthdate, personal ID, etc.) for all their site user lifetime as their angagement will graduate (or recede).

Many thanks for qualified reply... ;-) [email protected]

Man, you saved me days of work.
I had implemented a (not so reliable) solution for Drupal6 with auto groups / auto roles using hooks and hiding/showing fields... but your solution is so smart, thank you ^^

Though Drupal 7 is full of useful and next generation features, still it is a little bit complex like the previous versions. The problem & solution about managing multiple users is really a headache. But as one gradually follow the steps mentioned here, it will be very easy for him to solve the same. password manager

Hi, thanks for a great guideline. It was very helpful. My question is: Do you know how can I put profile (from Profile2) edit form to a user account edit form? There are two (or more) buttons and you have to edit it one by one... I wanna save all information together... Thanks for responding and one more for this article :-)

Hi, thanks for a great guideline. It was very helpful. My question is: Do you know how can I put profile (from Profile2) edit form to a user account edit form? There are two (or more) buttons and you have to edit it one by one... I wanna save all information together... Thanks for responding and one more for this article :-)

It seems too easy to creates the two user groups account by following the 11 steps as described by you in the above article. Never thought that it really will be that easy. So thanks a lot.
whosin

I followed all the step by step and set it all up but it does not solve the issue, when I click create new account on the login page it takes me to the default user/register and all I see is the default registration page none of my field for each any of the profile type shows, how can I make the user choose a role and then get redirected to the correct registration form?

Always find your stuff quite impressive, madman. Though lot of people face technical difficulty while doing something in Drupal. But believe, it is a great CMS. Certainly anyone will feel the initial awkwardness due to its vast application potential. But after through experience, you have to love it. Joshua Warren

HI

Thanks for a great Techi site!

I've followed your steps and are rearing to go but having difficulty setting up the fields for a profile under manage fields. I'd like to add a phone number field but the Number field type is missing on the Field Type dropdown. On a closer so is date, email and some other basic field types.

Have you come across this before? Your help much appreciated ;)

Thank you

I don't think I've tested it with files fields, but I would expect all field types to work. Please file a bug in the issue queue (with more details) if you'd like this looked into.

Hi
I followed all the steps here, and have my registration page at mysite/wpdocs/register, but this also shows the default registration form. Is there a way to not show that, and only my custom registration form?
Thanks

If you didn't show the default registration form, the user wouldn't be able to fill out the email, username, and password fields, which are required. It's possible to create a feature that would remove only the fields attached to the core user profile, but I would suggest just using hook_form_alter() to take care of this.

Would this module allow my already users to register for a new role? Say a student registering to be an assistant or something along those lines.

Sorry. Since this relies up on the user_register_form, it is only available to anonymous users.

... to create a specific login form (as a block, to display in sidebar) which will submit to the profile-specific login of this module?

This feature is in development on the 7.x-2.x. It's mostly working, but I've run out of time to complete the development. Please feel free to download it (via git) and help bring it the last few steps.

to edit the fields from the profile?

when I click on the "Edit" tab (once profile-specific user has logged in), I only see the standard user edit fields, not the ones I specified for the profile ...?

For example I have specified (in Structure -> Profile Types) that there's a field "Facebook page" for profile "Vendor", but when I log in as that user, I can't see the edit feature for this field anywhere?

Any help much appreciated,
gvanto

Excellent post and very helpfull to me .. Thanks folks

I have created a new profile type.(mydomain.com/newprofiler/register). i want to display this regisrtaon form(along with newly added fields) in my custom block. i tired very hard. but no luck.
Any help!!

thx for the work, this is a great module. looking forward to the 7.2/x branch

Thanks for this very useful info, however I dont see where I can display options for Member A and Member B to be presented with the different registration paths. The user login block only provides the default "Create User account" link which only links to one option. Am I overlooking something?
Thanks

The current 7.x-1.x version creates only new registration paths (page callbacks) and does not modify the registration block. The 7.x-2.x version, which is not production ready, will modify the blocks as well.

The idea of your blog is extremely fresh, I'm sure that the visitors that read your blogs will definitely take pleasure from your content and pointers.

Hi Matt.
About step 7 of TLDR, "Enter a URL path to use for this profile type, e.g., 'consumer/register'":
Where the URL should point to?
A custom form registration?
If yes, the form should be created from scratch? Have you some suggestion for a tutorial to help me in this task?
Thanks!

You should enter a URL that is not being used by any other module. Profile2 Registration path will the automatically generate a registration form at that path, along with the attached profile2 fields.

hi
how can i change default register path below login form block to a node
so user can see a list of register types(like customer account,business account...)
and can click to register from page link and redirect to that register page
thanks

What would be cool is if you could have multiple users per profile... Which would easily create a group solution...

That doesn't seem to fit with Profile2's intended purpose. If you'd like multiple users to share an entity, I'd suggest using Organic Groups, entity reference, node reference, or user reference.

Newb Question: When using this...
There is a simple drop down on the click selection that loads another field ... how do you do that?

If you're interested in an out-of-the-box solution, I'd look at Conditional fields. However, that does not have a stable release yet.

The more directly, reliable, but more advanced way to do it would be to use hook_form_alter() to modify the form. Just add an appropriate #states attribute to the form element in question.

I am using this module but I am stuck with a problem of separating profile2 fields from default User sign up form. When I created this specific profile2 form I check the option "Show during user account registration." Which disappeared after that. This is a kind of bug not sure how to deal with this.
Since, I want a multipage/step sign up, that would also help if Default Drupal user account creation form can be added as a page/step 1. Which I again couldn't find a solution.
Please help, which suggestions.

Thanks,

If you have a support request for Profile2 Registration Path, or you would like to report a bug, please do so in the issue queue. I will respond to such requests there.

Thanks for the detailed post; exactly what I was looking for!

If you want to send different welcome email messages for different registrants what is currently the best way to implement this?

Best, Paul

I would suggest using the rules module.

Thanks for the feedback O /

I am new to drupal, and I just started tinkering with it today. I heard about profile2, and this module that compliments it is definitely what I was looking for, so great job!

My question now is, how can a "consumer" view their profile page, and update the fields. Let's say they have a bio, and the initial one isn't good enough that they would want to revise it, and update it? Or what if there is an address field that needs updating? Can this be done with profile2 and your module?

Thanks in advance!

Yes, profiles can be edited by whomever is granted with the appropriate permissions.

I was looking for solution for few days on a project, but accidently, I read this, and here's the one I was looking for.. thank u very much

I used Profile2path module, and login destination module to redirect users to the profile page. In addition I add a sub menu block on each profile using views ( filter by current log in user- profile = (role assigned), but this can also be done using rules either way.

The new Profile Type has fields from the default profile type with no way to remove them.

I see only a problem in this module (maybe It's a problem only for me, I really don't know) when I install and configure Profile2 and Profile2 Registration Path I create two diferents path http://localhost/role1/register and http://localhost/role2/register but http://localhost/user/register still there and working.

It's a problem for me and I can't see a workround for this.
The best solution I think is to have the possibility to select the role in http://localhost/user/register e have personalized fields for role after the selection and before the registration.

I just came across this issue. All I did was add this to my .htaccess
Redirect /user/register /

the "/" just redirects to the homepage, you could do something like

Redirect /user/register /content/registration-options

Hope this helps!

how to separate label and text by drupal render.

Hi this is great module but main problem with edit profile.How to edit user profile.

Great module great work, I just struck up with the proifle2 module itself, but this module did all my work. I just have one question, I have created 3 profiles (Teacher, student, parent). How to parent get the information about his child based on the admission number, I worked on views to do it , but i couldn't able to figure out it.

Thanks.

Maybe I missed something and I apologize if I did but when creating my path on the Profile Types settings page I put inthe word say "barber" in the open box, assuming this creates a the path "mysite/barber/register". However when I log out and go to this page I get a Page Not Found error.
Maybe its a step I missed or something I did not understand in the hep text..Any information would be appreciated. Thanks!

is there a way to hide some fields in the profile2 registration form ?

Use field permissions module. Hide the fields you want for anonymous users.

Thanks for writing this module, going to try it out right away!

I've got two different signup forms on my site, one of which is very long. I'd like to override each form to style them individually, is there a way to have a separate template for each form? I have a consumer/register path and a business/register path. I apologize if this is a bit of an annoying question, this is my first time using this module, any help would be greatly appreciated!

How can we allow user to edit other user roles profile 2 info. If i do so profile 2 get associated with user who is edit that profile 2.

Hi, thanks for this great module! Do you see any way to allow for different account verification methods based on the role?

Setup is the following:
I have two roles (normal user, specific role) with separate profiles and two different registration pages. I would like to allow normal users to register without admin approval, but having admin approval necessary for specific role. I couldn't find a module up to now. Do you know of any solution for that?

Thanks a lot, it was exactly what I needed.

Needed a module for my new project. Thanks a ton. Keep up the good work.

Regards,
Akhilesh

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.