Tell us what you are trying to do?
I would like to create a form to change user's role after submitting the form.
e.g. If a customer fill in the form with driver's lic number and submit, the customer's role gets promoted to agent role.
Is there any documentation that you are following?
https://toolset.com/forums/topic/change-user-role-with-cred-form/
Do I just need to replace form ID and value "inventory_admin" on the code to my specific site?
Is there a similar example that we can see?
I have been using this but I would like to do the same thing inside of Toolset.
hidden link
What is the link to your site?
Please let me know.
Thank you!
Luo Yang
Supporter
Languages:
English (English )
Chinese (Simplified) (简体中文 )
Timezone:
Asia/Hong_Kong (GMT+08:00)
Hello,
In your case, you need to try these:
1) Replace form ID with your editing user form's ID
2) Check if the driver's lic number field is empty
3) Replace the "inventory_admin" with your custom user role slug, for example your custom user role's title is "my role", it should be "my_role"
Hello Yang,
Thank you for the information.
After I applied your suggested steps.
I still cannot perform what I inteded to do.
After I submit the form, the page shows the message as I set at the form setting page. But the role is still the same as before.
I had a plug in conflict issue, so I disabled all other unrelated plugins and tried it again, but the code still doesn't work.
Could you help me on this litte more. I can provide the log in infor for the site.
Luo Yang
Supporter
Languages:
English (English )
Chinese (Simplified) (简体中文 )
Timezone:
Asia/Hong_Kong (GMT+08:00)
Please provide your website credentials in below private message box, also point out the:
1) The problem page URL, where I can submit the form
2) The post form URL
3) Where I can edit your PHP codes,
Thanks
Luo Yang
Supporter
Languages:
English (English )
Chinese (Simplified) (简体中文 )
Timezone:
Asia/Hong_Kong (GMT+08:00)
I have tried the credentials you provided above, it requires Two-Factor code, so I can not login your website, please check it, you can also setup another test site with same form settings, then provide the test site credentials in below private message box.
I disabled 2FA now. Please try again.
Luo Yang
Supporter
Languages:
English (English )
Chinese (Simplified) (简体中文 )
Timezone:
Asia/Hong_Kong (GMT+08:00)
Thanks for the details, I have changed your PHP codes from:
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
wp_update_user ( array ( $user_id, 'role' => 'agent' ));
To:
$u = new WP_User( $post_id );
$u->set_role( 'agent' );
In Toolset user form, the first parameter is user's ID actually.
More help:
https://developer.wordpress.org/reference/functions/wp_update_user/
Hi,
How do I add another code for form ID 8853 and user role "business_owner"?
Luo Yang
Supporter
Languages:
English (English )
Chinese (Simplified) (简体中文 )
Timezone:
Asia/Hong_Kong (GMT+08:00)
You can modify those codes like this:
...
if ($form_data['id']=='8853')
{
$u = new WP_User( $post_id );
$u->set_role( 'business_owner' );
}
...
My issue is resolved now. Thank you!