Skip Navigation

[Resolved] Get Auto-generate Username on cred_save_data

This support ticket is created 5 years, 2 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 5 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#1365611

Hi, I created a User Add form with Auto-generate Username. Then I need to get the Username on cred_save_data. I tried with
$user_login = $_POST['user_login'];, but it doesn't work.

can you help me?

#1365989

Hi Umberto,

Thank you for contacting us and I'd be happy to assist.

Since the username is automatically generated, it is not available in the form's submitted data ($_POST).

To get it, you can use WordPress' "get_userdata" function.
( ref: https://developer.wordpress.org/reference/functions/get_userdata/ )

Example:


add_action('cred_save_data', 'user_form_data_action',10,2);
function user_form_data_action($post_id, $form_data)
{

	if ($form_data['id']==1234)
	{
		$user_obj = get_userdata( $post_id );
		$usernanme = $user_obj->user_login;
	}

}

Note: you'll replace "1234" with the ID of your actual form.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar