User role based on the answers

By: Lacombe Alexandre | Asked: 07/30/2022
ForumsCategory: How-toUser role based on the answers
Lacombe Alexandre asked 2 years ago
Hi there ! I use formidable form and I create user accounts using a form. The problem is that I'm setting a different user role based on the answers in this one. I can't set a specific role based on the answers, did you find a solution?   Thank you and have a nice day everyone!
2 Answers
Bobby Clapp answered 2 years ago
The only way I see this happening is with this code snippet -> https://formidableforms.com/knowledgebase/user-registration/#kb-set-the-user-role. If multiple answers define the role, you will have to code out that logic.
Lacombe Alexandre replied 2 years ago

Hello and thank you for your answer !
I also thought it could have been that but it doesn't work on my end.
It systematically puts the same role "subscriber".

Registration takes place on this page : https://lagora33.com/jentre-dans-lagora-33/

Lacombe Alexandre replied 2 years ago

It's ok it works. Thanks a lot !

Victor Font answered 2 years ago
Here's a tutorial: https://formidable-masterminds.com/change-wordpress-user-role-when-editing-field-in-a-view/
Lacombe Alexandre replied 2 years ago

Hello and thank you for your answer.
Unfortunately this solution only works if the person submits an answer when he is already connected. This is a form submission without an account.

Victor Font replied 2 years ago

That's not true. People do not have to be logged in for you to create roles for their accounts when using the user registration add-on.

I assign multiple roles to developers depending on the choices they make in the registration form when they join the Formidable Masterminds Developers Directory. This is during the account creation process before they are logged in. The code I shared with you can be adopted to suit your need.

You have to use the frm_after_create_entry and frm_after_update_entry hooks. The code in the article should be enough to get you started if you're a WordPress/PHP developer because you have to use the WordPress user_meta functions to add, update, get, or delete roles on demand.

You should also know that if you use the email verification process in the registration add-on, there's a bug in the add-on that deletes all user roles when it changes "pending" to "subscriber". The bug was reported to Strategy 11. I don't know if it's been fixed yet. If the bug hasn't been fixed, it's necessary to create a work around that resets the roles in the frmreg_after_create_user action.

If you're not comfortable developing and testing this much code, I suggest you consider hiring someone to help if you don't find the starter code helpful. This is a good starting point:
https://formidable-masterminds.com/developers-directory/. Plan for 8hrs of developer time as your budget.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right