Hi all

I'm trying to make a module that alters the registrationproces so the username is the same as the users email. To stop the namefield from showing up I inserted this into my custom modules
hook_form_alter

if($form_id == 'user_register') {
	
		unset($form['account']['name']);
  }

and the to avoid that the validation reports that the username is empty, I inserted this into hook_user

if($op == 'validate') {
		
		
		$edit['name'] = $edit['mail'];
		$account['name'] = $account['mail'];
		
}

this works, but it gives me the error below, which I think is wierd, because if I don't unset the namefield, and enter the same email in both email and name, this error doesnt occur.

user warning: Duplicate entry '' for key 2 query: INSERT INTO users (mail, pass, init, status, uid, created) VALUES ('fdasaaa@example.com', '09b0f27498e319464775226798ae52a0', 'fdasaaa@example.com', 1, 114, 1173891868)

Any help wil be greatly appreciated!!

Best,
/Johs.

Comments

xweb’s picture

How did you go with this?

xweb

johsw’s picture

but I just kept both the name and validated them against eachother. I used the hook_user in one of my cutom modules. This is the code

	if( $op == 'validate') {
	
			if(array_key_exists('name', $edit) || array_key_exists('mail', $edit)) {
			
				if($edit['name'] != $edit['mail']) {
	  
					form_set_error('name', 'Username and email do not match');
					form_set_error('mail', ' ');
					
				  }
			
	}

Best,
/J.

Christopher Herberte’s picture

A similar thread also Email for username. at http://drupal.org/node/133038 -
Chris.