I'm working on a site where I have a form that includes a liability waiver and rules. I'm using the members plugin for role management. I'd like to change a user's role automatically once they have completed the form. Is this possible?
Thanks!
I'm working on a site where I have a form that includes a liability waiver and rules. I'm using the members plugin for role management. I'd like to change a user's role automatically once they have completed the form. Is this possible?
Thanks!
This isn't currently a feature. But you could certainly do it using the available hooks. You could use the gform_pre_submission filter and custom code that you write that gets the user's id if they are logged in and updates their role.
interesting... if anyone attempts this I would like to know. I have the same issue wherein I have 3 user roles and they should be at 3 different WP Admin Levels (subscriber, contributor, editor).
I will look into that hook to see if I can do anything though I am pretty dumb when it comes to coding stuff like this.
Anyway to get a small example Carl?
I don't currently have an example as this specific functionality isn't something i've seen anyone on the forum implement before. But any developer who knows how to update a WordPress role using PHP shouldn't have any problems putting together this type of customization using available hooks.
Thanks Carl, so far the Gforms plugin has saved me weeks of custom development. Great job to all who worked on this. bunch of smarty pants.
I'll see if I can have someone on our team post a quick code snippet on how to change the user's role when a form is submitted and the user is logged in.
Is there any updates to this request?
We would also like the user role to be changed when they register with our site using GF ...
Our second inquiry as to when this feature may be added (updated) or if GF could post a code snippet.
Hi Guys,
Here is a snippet that will allow you to update the logged-in user's role after the form has been submitted. If the user is not logged in, nothing will happen:
This would go in your theme's functions.php file.
Thanks! Will let you know if we encounter any issues!
Hi David
I want to create a form where the user have the option to upgrade to either a Eg. Contributor or Editor Role
So the form will have a dropdown or something to give him this option
Any chance you could give me the code for this?
Hi Jacques,
Currently there is no simple way to accomplish conditional roles. If you are interested in coding a custom solution, I'd be happy to give you some pointers.
Hi,
I would like to revive this old post.
Currently using the latest gravity forms and user registration addon, i have been able to get all of the following working:
user registers using 'form 1' which creates user and sets user role to 'Pending'
admin gets email, verifies user info, uses 'New User Approve plugin' to approve, user role gets set to 'Subscriber', and user gets new password and login info by email
on user login, 'Theme My Login plugin' pushes user to 'form 2' which 'updates' user info, displays 'thank you' page that automatically logs user out
*** HERE is where I need help!... on 'form submission' I would like the following to happen:
user role set to 'None'
I tried the example posted by David Smith here:
http://pastie.org/2874838
Placed in my functions.php and adjusted to proper form number, but it is not changing the user's role.
Just wondering if anyone got this to work? What am I missing?
Thnx
This code will work, but you need to change the name of the hook from gform_post_submission to gform_after_submission.
Ok, I have tried changing that and a few other things that I suspected might be causing this not to work. I am questioning if
A) it is properly pulling the user_id?
B) it is supposed to be in functions.php? (maybe in form_display.php instead?)
Here is the code with edits commented out:
http://pastebin.com/N8rP1qsA
Thnx
The code should be in your current theme's functions.php
On line 8, add an echo statement: echo $user_id; and see if it contains the proper user ID. That will also show you that the code is being processed for sure.
OK, I updated the code on my pastebin to reflect what I am currently testing with.
I have reverted back to using:
$user_id = get_current_user_id();
I added the echo $user_id;
I was pushing to a display page, so I changed to a simple msg for testing.
On complete, I only see my simple msg and no user_id
That would explain why it's not working. However, we need to figure out why $user_id is empty.
Instead of using get_current_user_id() can you try this code (just as a test)?
[php]
global $current_user;
get_currentuserinfo();
$user_id = $current_user->ID;
Are you doing this in the theme's functions.php or a plugin you created?
Is the user already logged in when attempting to use this functionality? As David stated previously "If the user is not logged in, nothing will happen:"
Yes, form is requiring user to be logged in, and user is logged in.
I am using my current theme's functions.php, not a plugin.
I have replaced 'get_current_user_id()' with your snippet.
Result still does not display user_id on form complete, user is still set to Subscriber.
Thnx
I'm still looking to resolve this issue
Thnx
Just wanted to update this post.
We were having issues with mixing data input form with file uploads on one form, so I made another form to be loaded after the data input form was complete, that is just for photo uploads.
When I created the User Registration connection to Update User, I realized I could choose a different Role from the dropdown that changes the Role on form complete.
The only problem now is that I wanted to deny user the ability to log in, which this does not fix...
I will investigate creating a new role that denies login.