Registration - Username Question

Hi,

I would prefer to not require the person registering to choose a username and simply enter their email.

Can the email be applied to the username?
If not, can the username field be defined as an email address and applied also to the email field?

Or… let me know what you think.

Thanks,

You can create a username based on the email address alone, using this filter:

Definitely! All my users have their email as their login. It should look something like this:

Hi Chris,

I implemented this (https://docs.gravityforms.com/gform_username/) in the theme’s functions.php and it established the username OK.

I hadn’t noticed the comment to associate the form ID to the first name and last name field for a few minutes so was confused. But it worked out. Thanks.

Hi,

While your proposed configuration seems logical, for some reason it would not establish the username as the email for me. I appreciate your example however as it helped me understand how to handle other details (i.e.: establishing display name and nick name)

Huh, that’s odd. The other thing you could do is something I did for my purchasing form. I don’t use the User Registration at all. If the vendor doesn’t exist it just creates a new one with an After Submission function. I’ve left out a lot of excess variables, but I usually use $user_email = rgar( $entry, '9' ); for that. You can also also tell it to update data if the User already exists, you just need to put a conditional in with a bunch of update_user_meta function calls.

add_action( 'gform_after_submission_50', 'after_submit_50', 10, 2 );
function after_submit_50( $entry, $form ) {
  if( $form['id'] == 50 ){
//Create new vendor
		$user_email = rgar( $entry, '9' );
		$user_id = email_exists( $user_email );
	
	if( !$user_id ){
	$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
	
	$userdata = array(
	  	'ID'                    => $user_id,
		'user_pass'             => $random_password,   //(string) The plain-text user password.
		'user_login'            => $user_email,   //(string) The user's login username.
		'user_nicename'         => $user_name,   //(string) The URL-friendly user name.
		'user_url'              => $user_url,   //(string) The user URL.
		'user_email'            => $user_email,   //(string) The user email address.
		'display_name'          => $user_name,   //(string) The user's display name. Default is the user's username.
		'nickname'              => $user_name,   //(string) The user's nickname. Default is the user's username.
		'first_name'            => $v_fname,   //(string) The user's first name. For new users, will be used to build the first part of the user's display name if $display_name is not specified.
		'last_name'             => $v_lname,   //(string) The user's last name. For new users, will be used to build the second part of the user's display name if $display_name is not specified.
		'rich_editing'          => 'false',   //(string|bool) Whether to enable the rich-editor for the user. False if not empty.
		'use_ssl'               => 'true',   //(bool) Whether the user should always access the admin over https. Default false.
		'show_admin_bar_front'  => 'false',   //(string|bool) Whether to display the Admin Bar for the user on the site's front end. Default true.
		'role'                  => 'vendor',   //(string) User's role.
		'locale'                => '',   //(string) User's locale. Default empty.
	  );

			$user_id = wp_insert_user( $userdata );
		if($user_id){
			update_user_meta( $user_id, u_phone1, $v_phone );
			update_user_meta( $user_id, billing_address_1, $v_address1 );
			update_user_meta( $user_id, billing_address_1, $v_address1 );

			update_user_meta( $user_id, billing_address_1, $v_address1 );
			update_user_meta( $user_id, billing_address_2, $v_address2 );
			update_user_meta( $user_id, billing_city, $v_address_city );
			update_user_meta( $user_id, billing_postcode, $v_address_postal );
			update_user_meta( $user_id, billing_country, $v_address_country );
			update_user_meta( $user_id, billing_state, $v_address_country );
		}
	}
 }
}

Best of luck!

1 Like