Skip Navigation

[Resolved] CRED User form – new user email as username

This support ticket is created 2 years, 3 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Shane 2 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#2311253

Hi there,

Can you help me with a function that will set the new user "username" as the email address when the form saves?

Many thanks

#2311327

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

Thank you for getting in touch.

add_action('cred_save_data', 'update_username',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12)
    {
        if (isset($_POST['user_email']))
        {
           wp_update_user( array( 'ID' => $post_id, 'user_login' => $_POST['user_email'] ) );
        }
    }
}
 

Please try the above code and let me know if it helps. Replace the 12 with the ID of the form that you want this code to be triggered for.

Finally this code can be added to Toolset -> Settings -> Custom Code and ensure that its activated.

Please let me know if this helps.
Thanks,
Shane

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.