I am trying to: create users from a CRED user form but I want to set their username to email address and set nickname and displayname to first name.
Is this possible with CRED forms alone? If not, is there an API for user forms? The CRED API documentation seems to only cover post forms.
I'd also like to change the wording on the password hint to 8 characters instead of 12. I can force this with javascript and/or CSS but it'd be nice to get it correct in the first place instead of correcting it.
I managed to put email address in as username by asking for username in the username part of the form but I don't want to ask the user for email twice and I don't want to ask for nickname or displayname at all, I just want to get the first name and save it as first name, display name and nickname. This would be sort of like setting the cred_field value for the display name and nickname to the value of the first name field but it isn't known when the form is being rendered so it needs to be set when the form is submitted.
Yes you can actually do this with our CRED API save data hook.
Take a look at this example.
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($new_user_id, $form_data)
{
// if a specific form
if ($form_data['id']==1370)
{
if(isset($_POST['first_name']) && isset($_POST['last_name'])){
update_user_meta( $new_user_id, 'nickname', $_POST['first_name']."".$_POST['last_name']);
}
}
}
Where it updates the user nickname to the first and last name.
Please let me know if this example helps.
Thanks,
Shane
Thanks Shane, this worked great and I was able to add the other things I needed it to do. All the CRED API examples for cred_save_data are for posts, not users. It would be good to add an example like this one into the documentation.
This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.