This support ticket is created 7 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I created a user field, called profession, for selecting the role. This is my code:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {
if ($form_data['id']==194) {
if (isset($_POST['profession'])) {
$u = new WP_User($post_id);
$u->set_role($_POST['profession']);
}
}
}
I'm assuming that profession is a custom field on your form to select the user role correct?
If so then the custom field should be named wpcf_professions . If that does not work could you let me have a look at the form so I can see the appropriate name for the form field.
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {
if ($form_data['id']==199) {
if (isset($_POST['wpcf_profession'])) {
$u = new WP_User($post_id);
$u->set_role($_POST['wpcf_profession']);
}
}
}
Yes this is the same however if your create the roles using ACCESS then when you setup a roles custom field for your form, the slug of the roles must be the same as value field of your custom fields in order for it to work.
So far you have things setup correctly , all you need to do is to ensure that your slugs match.
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {
if ($form_data['id']==5) {
if (isset($_POST['wpcf-profession'])) {
$u = new WP_User($post_id);
$u->set_role($_POST['wpcf-profession']);
}
}
}
However, when my new user is created, they are given a role of 'none.' I believe I'm using the same slug for both the custom field role values and for the User Role values created in Access. One thing to note is that I am using Checkboxes as the field type. Please advise.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.