Hi, if I call this code (extracted directly from help):

$values['name'] = 'robo-user';
$values['mail'] = 'robouser@example.com';
$values['pass'] = 'password';
drupal_execute('user_register', $values);  

the user is created, but the real password is only the first character fo the original password. So the user has to log-in with username 'robo-user', password 'p'. It has to be some problem with forms I think, because I catched the password value in the user_register_submit() function in the user module, and the password is already trimmed there.

Can someone help please? I need to be able to create users automatically...
B.

Comments

SpatnyNick’s picture

Hi, noone can help me?... Does someone of you use drupal_execute to create a user?

bs’s picture

did you set user email verification to no? otherwise drupal will create new password and also you need to pass $form['notify'] = true to send an email to the user.

SpatnyNick’s picture

Hi, thanks for the reply. Yes I disabled the mail verification... the password is everytime the firts letter of the password send to the form...

SpatnyNick’s picture

Finally I have found the problem I think. The calling function for user creation should look for example like this one:

function autousr_form_submit($form_id, $form_values) {
  $values = array();
  $values['name'] = $form_values['ico'];
  $values['mail'] = $form_values['mail'];
  $values['roles'] = array('4' => 'some def role'); 
  $values['pass']['pass1'] = $form_values['password']; 
  $values['pass']['pass2'] = $form_values['password']; 
  $values['notify'] = 'true';  // or delete this line if you do not want the mail notification
  drupal_execute('user_register', $values);
}

So, you have to use:

  $values['pass']['pass1'] = 'somepass'; 
  $values['pass']['pass2'] = $values['pass']['pass1'];

not only the:

  $values['pass'] = $form_values['heslo']; 

as it is presented in the api:
http://api.drupal.org/api/5/function/drupal_execute
it just doesn't work correctly.

I hope it will help someone.

Have a nice day!

willmoy’s picture

Category: bug » support
Status: Active » Closed (fixed)